Python Forum
Using Python request without selenium on html form with javascript onclick submit but
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Python request without selenium on html form with javascript onclick submit but
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML multi select HTML listbox with Flask/Python rfeyer 0 773 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Flask Basics request.form ifigazsi 0 500 Feb-09-2021, 09:05 AM
Last Post: ifigazsi
  Saving html page and reloading into selenium while developing all xpaths Larz60+ 4 1,773 Feb-04-2021, 07:01 AM
Last Post: jonathanwhite1
  Flask request.form ifigazsi 2 516 Feb-02-2021, 11:56 AM
Last Post: buran
  Using python within an html form t4keheart 5 1,220 Aug-17-2020, 12:28 PM
Last Post: t4keheart
  POST request with form data issue web scraping hoff1022 1 1,120 Aug-14-2020, 10:25 AM
Last Post: kashcode
  Jinja sort values from request.form SpongeB0B 2 602 Jul-26-2020, 07:41 AM
Last Post: SpongeB0B
  [FLASK] checkbox onclick event Mad0ck 2 1,558 May-14-2020, 09:35 AM
Last Post: Mad0ck
  Python Request's Proxies not working. Fudster 1 4,187 May-01-2020, 06:42 AM
Last Post: buran
  question about using javascript on python selenium Kai 1 704 Apr-12-2020, 04:28 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020