Python Forum

Full Version: Using Python request without selenium on html form with javascript onclick submit but
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to submit a form that uses onclick javascript submit function and i think when the submit function is invoked it generates a url for the next page that is linked to the action of the form.

What this means is that the action on the form actually has a url on it, that when submit is clicked, that same url is modified to add some variables through get in the javascript submit button function.

The Form looks like this:

HTML
<form id="alepo-searchUserAccounts-fm" name="_homepageannoncement_WAR_homepage5231_fm" action="https://crm.spectranet.com.ng/group/admin/add-end-customer?p_p_id=customerdetails_WAR_ase5231&amp;p_p_lifecycle=0&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_pos=1&amp;p_p_col_count=2&amp;_customerdetails_WAR_ase5231_struts_action=%2Fase%2Fcustomerdetails_view&amp;_customerdetails_WAR_ase5231_CMD=view" method="POST" autocomplete="off">	   	<table class="taglib-search-iterator" width="90%">	<tbody><tr><td valign="top">	<fieldset>	<legend>Account Quick Search</legend>	<table class="taglib-search-iterator">
           	<tbody><tr><td><label>User ID</label></td><td><input type="text" class="search" name="userId" size="30"></td></tr><tr><td><label>Primary Email</label></td><td><input type="text" class="search email" name="email" size="30"></td></tr><tr><td><label>Primary Mobile Number</label></td><td><input type="text" class="search mobile" name="userdetails.mobile" size="30"></td></tr><tr><td><label>IMSI</label></td><td><input type="text" class="search" name="imsi" size="30"></td></tr><tr><td><label>MSISDN</label></td><td><input type="text" class="search" name="msisdn" size="30"></td></tr><tr><td><label>IMEI</label></td><td><input type="text" class="search" name="subscriptions.customfield1" size="30"></td></tr><!--<tr><td><label>Static IP Address</label></td><td><input type="text" class="search ipAddress" size="30" name="userIp" /></td></tr><tr><td><label>External Charging Identifier</label></td><td><input type="text" class="search" size="30" name="externalChargingIdentifier" /></td></tr>-->
          	</tbody></table><br>	<hr>	<br>	<div class="actions">	<input id="search-button" type="submit" value="Search Criteria" onclick="return createUserSearchURL('alepo-searchUserAccounts-fm', '_customerdetails_WAR_ase5231_');">	<input id="reset-button" type="button" value="Reset" onclick="resetForm('alepo-searchUserAccounts-fm')">	</div></fieldset>	</td></tr></tbody></table></form>
AND THE Submit function found in the above form "createUserSearchURL" looks like this:

JAVASCRIPT
<script type="text/javascript">/*<![CDATA[*/function createUserSearchURL(e,a){var d="https://crm.spectranet.com.ng/group/admin/360view?p_p_id=customerview_WAR_ase5231&p_p_lifecycle=0&p_p_state=normal&p_p_col_id=column-1&p_p_col_count=2&_customerview_WAR_ase5231_struts_action=%2Fase%2Fcustomerview_action&_customerview_WAR_ase5231_CMD=view";e="#"+e;var b=$(e).attr("action");var c="AND 1=1";if($(e).valid()){$(".search",e).each(function(){if($.trim(this.value).length>0){b=b+"&"+$(this).attr("name")+"="+$(this).val();if($(this).attr("name")=="userId"){c=c+" AND "+$(this).attr("name")+" like '"+$(this).val()+"%'"}else{c=c+" AND "+$(this).attr("name")+" = '"+$(this).val()+"'"}}});$.ajax({url:"/homepage-5.2.3.1/html/homepage/checkUsers.jsp",type:"GET",data:{"filter-clause":c},dataType:"json",async:false,success:function(f){if(f.directRedirect==true){d=d+"&userIndex="+f.userIndex+"&_customerview_WAR_ase5231_recId="+f.userIndex+"&userId="+f.userId+"&refreshTime=1610198326524";b=d}},error:function(f,g){}});$(e).attr("action",b);return true}return false}function createSearchURL(c,a){c="#"+c;var b=$(c).attr("action");if($(c).valid()){$(".search",c).each(function(){if($.trim(this.value).length>0){b=b+"&"+$(this).attr("name")+"="+$(this).val()}});$(c).attr("action",b);return true}return false}function spliten(){var d=105;var a="...";var c="more";var b="less";$(".more").each(function(){var g=$(this).html();if(g.length>d){var i=g.substr(0,d);var f=g.substr(d-1,g.length-d);var e=i+'<span class="moreellipses">'+a+'&nbsp;</span><span class="morecontent"><span>'+f+'</span>&nbsp;&nbsp;<a href="" class="morelink">'+c+"</a></span>";$(this).html(e)}});$(".morelink").click(function(){if($(this).hasClass("less")){$(this).removeClass("less");$(this).html(c);popup}else{$(this).addClass("less");$(this).html(b)}$(this).parent().prev().toggle();$(this).prev().toggle();return false})};/*]]>*/</script>
I do not want to use selenium for this cuz i think selenium needs wait time which i cannot determine cuz people use different types of internet ISP with varying speeds. But i think with request everything is done in the background at runtime