![]() |
Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered (/thread-20104.html) |
Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - NSearch - Jul-28-2019 I am attempting to navigate a web page with what I believe to be javascript triggers that are not being set properly when submitting (or clicking) the submit button. I have tried clicking the button by id, by name, by xpath using .click() and using ActionChains to move to and click the element. All produce the same result: the form submits, but displays "system error has been encountered". When I click the back button and click the same button manually, the form submits successfully. I believe the problem lies in the javascript triggers - although I will say that I do not have any experience sending "commands" to javascript using webdriver. Any assistance would be very much appreciated. I have tried using webdriver for both Firefox and Chrome, with the same results. I am starting to think it has something to do with the token. Please help! Thank you Below is the javascript function checkAndSubmit(tNumber) { tNumber = tNumber.replace(/^\s+|\s+$/g, ''); var tNumberRegExp=/^(1z[0-9a-zA-Z]{16}|1Z[0-9a-zA-Z]{16}|[0-9a-zA-Z]{11})$/; if (tNumberRegExp.test(tNumber)) { document.forms[0].style.visibility="hidden"; document.getElementById("please_wait").style.visibility="visible"; window.setTimeout('showProgress()', 0); return true; } else { document.getElementById('errorMessage').innerHTML= 'The number you entered is not valid'; return false; } } function showProgress(){ var wg = document.getElementById("pinwheel"); wg.src=wg.src; }Below is the html <div class="mc2" id="user_input"> <form id="request" name="request" onsubmit="return checkAndSubmit(this.tNumber.value)" action="/ebilling/request.action" method="post"> <input type="hidden" name="CSRFToken" value="8be3e045-99b4-46f6-a6d9-f34e70017b96"> <table class="modulebackgroundcolor" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td>X. <a href="https://www.x.com/assets/resources/media/en_US/terms_service_us.pdf" target="_blank">x</td> </tr> <tr> <td>Please enter the TNumber (XXXXXXXXXXXXXXX or 99999999999) below to submit your request.</td> </tr> <tr> <td id="errorMessage" style="color: red;"> </td> </tr> <tr> <td> <input type="text" name="tNumber" size="30" maxlength="30" value="" id="request_tNumber"></td> </tr> <tr> <td>Note: XYZ.</td> </tr> <tr> <td>*XXX</td> </tr> <tr> <td> </td> </tr> </tbody></table> <div class="mb" align="right"> <h4> <span><input class="bSwan" type="button" value="Cancel" onclick="location.href='/ebilling/dashBoard.action?reportId=dashboardIncentiveRpt'"></span> <span><input type="submit" value="Submit" id="request_0" class="bSwan"> </span> </h4> </div> <br> <input type="hidden" name="_csrf" value="e7634769-8942-415f-b939-39e748359b81"></form> </div>Below is the javascript that I came across when looking through the inspection if (typeof document.attachEvent!='undefined') { window.attachEvent('onload',init); document.attachEvent('onmousemove',moveMouse); document.attachEvent('onclick',checkMove); } else { window.addEventListener('load',init,false); document.addEventListener('mousemove',moveMouse,false); document.addEventListener('click',checkMove,false); } var oDv=document.createElement("div"); var dvHdr=document.createElement("div"); var dvBdy=document.createElement("div"); var windowlock,boxMove,fixposx,fixposy,lockX,lockY,fixx,fixy,ox,oy,boxLeft,boxRight,boxTop,boxBottom,evt,mouseX,mouseY,boxOpen,totalScrollTop,totalScrollLeft; boxOpen=false; ox=10; oy=10; lockX=0; lockY=0; function init() { oDv.appendChild(dvHdr); oDv.appendChild(dvBdy); oDv.style.position="absolute"; oDv.style.visibility='hidden'; document.body.appendChild(oDv); } function defHdrStyle() { dvHdr.innerHTML='<img style="vertical-align:middle" src="../../_assets/images/info.gif"> '+dvHdr.innerHTML; dvHdr.style.fontWeight='bold'; dvHdr.style.width='150px'; dvHdr.style.fontFamily='arial'; dvHdr.style.border='1px solid #A5CFE9'; dvHdr.style.padding='3'; dvHdr.style.fontSize='11'; dvHdr.style.color='#4B7A98'; dvHdr.style.background='#D5EBF9'; dvHdr.style.filter='alpha(opacity=85)'; // IE dvHdr.style.opacity='0.85'; // FF } function defBdyStyle() { dvBdy.style.borderBottom='1px solid #A5CFE9'; dvBdy.style.borderLeft='1px solid #A5CFE9'; dvBdy.style.borderRight='1px solid #A5CFE9'; dvBdy.style.width='220px'; dvBdy.style.height='67px'; dvBdy.style.fontFamily='arial'; dvBdy.style.fontSize='11'; dvBdy.style.padding='3'; dvBdy.style.color='#003399'; dvBdy.style.background='#d4ccbf'; dvBdy.style.filter='alpha(opacity=100)'; // IE dvBdy.style.opacity='1.00'; // FF } function checkElemBO(txt) { if (!txt || typeof(txt) != 'string') return false; if ((txt.indexOf('header')>-1)&&(txt.indexOf('body')>-1)&&(txt.indexOf('[')>-1)&&(txt.indexOf('[')>-1)) return true; else return false; } function scanBO(curNode) { if (checkElemBO(curNode.title)) { curNode.boHDR=getParam('header',curNode.title); curNode.boBDY=getParam('body',curNode.title); curNode.boCSSBDY=getParam('cssbody',curNode.title); curNode.boCSSHDR=getParam('cssheader',curNode.title); curNode.IEbugfix=(getParam('hideselects',curNode.title)=='on')?true:false; curNode.fixX=parseInt(getParam('fixedrelx',curNode.title)); curNode.fixY=parseInt(getParam('fixedrely',curNode.title)); curNode.absX=parseInt(getParam('fixedabsx',curNode.title)); curNode.absY=parseInt(getParam('fixedabsy',curNode.title)); curNode.offY=(getParam('offsety',curNode.title)!='')?parseInt(getParam('offsety',curNode.title)):20; curNode.offX=(getParam('offsetx',curNode.title)!='')?parseInt(getParam('offsetx',curNode.title)):-50; curNode.fade=(getParam('fade',curNode.title)=='on')?true:false; curNode.fadespeed=(getParam('fadespeed',curNode.title)!='')?getParam('fadespeed',curNode.title):0.04; curNode.delay=(getParam('delay',curNode.title)!='')?parseInt(getParam('delay',curNode.title)):0; if (getParam('requireclick',curNode.title)=='on') { curNode.requireclick=true; document.all?curNode.attachEvent('onclick',showHideBox):curNode.addEventListener('click',showHideBox,false); document.all?curNode.attachEvent('onmouseover',hideBox):curNode.addEventListener('mouseover',hideBox,false); } else {// Note : if requireclick is on the stop clicks are ignored if (getParam('doubleclickstop',curNode.title)!='off') { document.all?curNode.attachEvent('ondblclick',pauseBox):curNode.addEventListener('dblclick',pauseBox,false); } if (getParam('singleclickstop',curNode.title)=='on') { document.all?curNode.attachEvent('onclick',pauseBox):curNode.addEventListener('click',pauseBox,false); } } curNode.windowLock=getParam('windowlock',curNode.title).toLowerCase()=='off'?false:true; curNode.title=''; curNode.hasbox=1; } else curNode.hasbox=2; } function getParam(param,list) { var reg = new RegExp('([^a-zA-Z]' + param + '|^' + param + ')\\s*=\\s*\\[\\s*(((\\[\\[)|(\\]\\])|([^\\]\\[]))*)\\s*\\]'); var res = reg.exec(list); var returnvar; if(res) return res[2].replace('[[','[').replace(']]',']'); else return ''; } function Left(elem){ var x=0; if (elem.calcLeft) return elem.calcLeft; var oElem=elem; while(elem){ if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderLeftWidth)))&&(x!=0)) x+=parseInt(elem.currentStyle.borderLeftWidth); x+=elem.offsetLeft; elem=elem.offsetParent; } oElem.calcLeft=x; return x; } function Top(elem){ var x=0; if (elem.calcTop) return elem.calcTop; var oElem=elem; while(elem){ if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderTopWidth)))&&(x!=0)) x+=parseInt(elem.currentStyle.borderTopWidth); x+=elem.offsetTop; elem=elem.offsetParent; } oElem.calcTop=x; return x; } var ah,ab; function applyStyles() { if(ab) oDv.removeChild(dvBdy); if (ah) oDv.removeChild(dvHdr); dvHdr=document.createElement("div"); dvBdy=document.createElement("div"); CBE.boCSSBDY?dvBdy.className=CBE.boCSSBDY:defBdyStyle(); CBE.boCSSHDR?dvHdr.className=CBE.boCSSHDR:defHdrStyle(); dvHdr.innerHTML=CBE.boHDR; dvBdy.innerHTML=CBE.boBDY; ah=false; ab=false; if (CBE.boHDR!='') { oDv.appendChild(dvHdr); ah=true; } if (CBE.boBDY!=''){ oDv.appendChild(dvBdy); ab=true; } } var CSE,iterElem,LSE,CBE,LBE, totalScrollLeft, totalScrollTop, width, height ; var ini=false; // Customised function for inner window dimension function SHW() { if (document.body && (document.body.clientWidth !=0)) { width=document.body.clientWidth; height=document.body.clientHeight; } if (document.documentElement && (document.documentElement.clientWidth!=0) && (document.body.clientWidth + 20 >= document.documentElement.clientWidth)) { width=document.documentElement.clientWidth; height=document.documentElement.clientHeight; } return [width,height]; } var ID=null; function moveMouse(e) { //boxMove=true; e?evt=e:evt=event; CSE=evt.target?evt.target:evt.srcElement; if (!CSE.hasbox) { // Note we need to scan up DOM here, some elements like TR don't get triggered as srcElement iElem=CSE; while ((iElem.parentNode) && (!iElem.hasbox)) { scanBO(iElem); iElem=iElem.parentNode; } } if ((CSE!=LSE)&&(!isChild(CSE,dvHdr))&&(!isChild(CSE,dvBdy))){ if (!CSE.boxItem) { iterElem=CSE; while ((iterElem.hasbox==2)&&(iterElem.parentNode)) iterElem=iterElem.parentNode; CSE.boxItem=iterElem; } iterElem=CSE.boxItem; if (CSE.boxItem&&(CSE.boxItem.hasbox==1)) { LBE=CBE; CBE=iterElem; if (CBE!=LBE) { applyStyles(); if (!CBE.requireclick) if (CBE.fade) { if (ID!=null) clearTimeout(ID); ID=setTimeout("fadeIn("+CBE.fadespeed+")",CBE.delay); } else { if (ID!=null) clearTimeout(ID); COL=1; ID=setTimeout("oDv.style.visibility='visible';ID=null;",CBE.delay); } if (CBE.IEbugfix) {hideSelects();} fixposx=!isNaN(CBE.fixX)?Left(CBE)+CBE.fixX:CBE.absX; fixposy=!isNaN(CBE.fixY)?Top(CBE)+CBE.fixY:CBE.absY; lockX=0; lockY=0; boxMove=true; ox=CBE.offX?CBE.offX:10; oy=CBE.offY?CBE.offY:10; } } else if (!isChild(CSE,dvHdr) && !isChild(CSE,dvBdy) && (boxMove)) { // The conditional here fixes flickering between tables cells. if ((!isChild(CBE,CSE)) || (CSE.tagName!='TABLE')) { CBE=null; if (ID!=null) clearTimeout(ID); fadeOut(); showSelects(); } } LSE=CSE; } else if (((isChild(CSE,dvHdr) || isChild(CSE,dvBdy))&&(boxMove))) { totalScrollLeft=0; totalScrollTop=0; iterElem=CSE; while(iterElem) { if(!isNaN(parseInt(iterElem.scrollTop))) totalScrollTop+=parseInt(iterElem.scrollTop); if(!isNaN(parseInt(iterElem.scrollLeft))) totalScrollLeft+=parseInt(iterElem.scrollLeft); iterElem=iterElem.parentNode; } if (CBE!=null) { boxLeft=Left(CBE)-totalScrollLeft; boxRight=parseInt(Left(CBE)+CBE.offsetWidth)-totalScrollLeft; boxTop=Top(CBE)-totalScrollTop; boxBottom=parseInt(Top(CBE)+CBE.offsetHeight)-totalScrollTop; doCheck(); } } if (boxMove&&CBE) { // This added to alleviate bug in IE6 w.r.t DOCTYPE bodyScrollTop=document.documentElement&&document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop; bodyScrollLet=document.documentElement&&document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft; mouseX=evt.pageX?evt.pageX-bodyScrollLet:evt.clientX-document.body.clientLeft; mouseY=evt.pageY?evt.pageY-bodyScrollTop:evt.clientY-document.body.clientTop; if ((CBE)&&(CBE.windowLock)) { mouseY < -oy?lockY=-mouseY-oy:lockY=0; mouseX < -ox?lockX=-mouseX-ox:lockX=0; mouseY > (SHW()[1]-oDv.offsetHeight-oy)?lockY=-mouseY+SHW()[1]-oDv.offsetHeight-oy:lockY=lockY; mouseX > (SHW()[0]-dvBdy.offsetWidth-ox)?lockX=-mouseX-ox+SHW()[0]-dvBdy.offsetWidth:lockX=lockX; } oDv.style.left=((fixposx)||(fixposx==0))?fixposx:bodyScrollLet+mouseX+ox+lockX+"px"; oDv.style.top=((fixposy)||(fixposy==0))?fixposy:bodyScrollTop+mouseY+oy+lockY+"px"; } } function doCheck() { if ( (mouseX < boxLeft) || (mouseX >boxRight) || (mouseY < boxTop) || (mouseY > boxBottom)) { if (!CBE.requireclick) fadeOut(); if (CBE.IEbugfix) {showSelects();} CBE=null; } } function pauseBox(e) { e?evt=e:evt=event; boxMove=false; evt.cancelBubble=true; } function showHideBox(e) { oDv.style.visibility=(oDv.style.visibility!='visible')?'visible':'hidden'; } function hideBox(e) { oDv.style.visibility='hidden'; } var COL=0; var stopfade=false; function fadeIn(fs) { ID=null; COL=0; oDv.style.visibility='visible'; fadeIn2(fs); } function fadeIn2(fs) { COL=COL+fs; COL=(COL>1)?1:COL; oDv.style.filter='alpha(opacity='+parseInt(100*COL)+')'; oDv.style.opacity=COL; if (COL<1) setTimeout("fadeIn2("+fs+")",20); } function fadeOut() { oDv.style.visibility='hidden'; } function isChild(s,d) { while(s) { if (s==d) return true; s=s.parentNode; } return false; } var cSrc; function checkMove(e) { e?evt=e:evt=event; cSrc=evt.target?evt.target:evt.srcElement; if ((!boxMove)&&(!isChild(cSrc,oDv))) { fadeOut(); if (CBE&&CBE.IEbugfix) {showSelects();} boxMove=true; CBE=null; } } function showSelects(){ var elements = document.getElementsByTagName("select"); for (i=0;i< elements.length;i++){ elements[i].style.visibility='visible'; } } function hideSelects(){ var elements = document.getElementsByTagName("select"); for (i=0;i< elements.length;i++){ elements[i].style.visibility='hidden'; } }Also there is some more java code that may be relevant var csrfParamName = "_csrf"; var csrfHeaderName = $("meta[name='_csrf_header']").attr("content"); var csrfValue = "cbceab72-b03f-4a52-8f36-e933fb41417b"; function addCSRFToForms(){ var forms = document.getElementsByTagName("form"); for(var i=0; i<forms.length; i++){ var csrfHidden = document.createElement("input"); csrfHidden.type = "hidden"; csrfHidden.name = csrfParamName; csrfHidden.value = csrfValue; forms[i].appendChild(csrfHidden); } } $(document).ready(function(){ $(document).ajaxSend(function(e, xhr, options) { //alert("ajax"); xhr.setRequestHeader(csrfHeaderName, csrfValue); }); addCSRFToForms(); });driver.get_cookies() returns the following: Quote:[{'domain': '.xyz.com', 'expiry': 1564931179, 'httpOnly': False, 'name': 'RT', 'path': '/', 'secure': False, 'value': '"sl=2&ss=1564326361157&tt=13690&obo=0&bcn=%2F%2F173c5b05.akstat.io%2F&sh=1564326376470%3D2%3A0%3A13690%2C1564326369405%3D1%3A0%3A7020&dm=xyz.com&si=2bd1575a-4b40-4bd7-b6f8-0664e85f27e5&ld=1564326376471&nu=&cl=1564326377146&r=https%3A%2F%2Fwww.xyz.com%2Flasso%2Flogin%3Fc7791874ad8eedf07039131f71d26468&ul=1564326377186&hd=1564326379541"'}, {'domain': 'www.apps.xyz.com', 'httpOnly': True, 'name': 'ebilling', 'path': '/', 'secure': True, 'value': 'loc5HkEm6LqUj1KbF46vHhbXwt-6d1Y1Imc7jPWURVqcM5tp7Mrc!-2116453065!2052880498'}, {'domain': '.xyz.com', 'httpOnly': True, 'name': 'session_xyz_com', 'path': '/', 'secure': True, 'value': '1564326378&_4Ln_W_JUOLnuSJVR0dKeka1cfovrjbFD7_6aJjFICw=&:qEMRA0rqcNdV8ZtVZ7IM_USeDZR1ilNlIugMEPfTcwpH_mcCA0Fo4tsds4GV1BA3wc2KsOR1CIFyNTnXeQCQyxz4FebCPqRbHyhkTK0DkdQ=&:OwJnRyKTOxG46-svqGXrP6xQcZYu_ViVxVLnYbwTKb_74VuLFaLZ8hFh1WApqhg2'}, {'domain': '.xyz.com', 'expiry': 1627444800, 'httpOnly': False, 'name': '_4c_', 'path': '/', 'secure': True, 'value': 'hZNta%2BM4EMe%2FyiFIX7W2niw5gVCatgc92C19gL4MsjRpTW3ZSEqyvdLv3lGShi4ct37j0cxv%2FiONRu9k%2BwKezFilpOBKaM1pfUpe4S2S2TsJrcu%2FDZmRRoBmsALHtKONplRCPVXNtFLCOrCOnJJfWUdzRrlQumb1xymx4yH%2FndjBAeqwaaEKhnT6F1dcUjTB5wpjyCIrzCCaUagFX1mD0lrrxlC3YsaJupFM0szd%2Fni8Xy6uLy5vf2LCS0pjnJXl2rcJ3GiChS5C2LQWimiLoU%2FB2cJDKpsyxnI9xjEMrmS0%2FOfhjBeMFrSMFasorbABQk2FPr%2B4W8zZSd%2B6ORXoVFpQLZmmmjJd8bquJZ8qJYQWdcWorE4u7q7n%2BWSPYLp23S8fIC5vrvKZD91V%2BFcIrEP3bc%2Fb7bbADRV26MvOxDiU3fDc%2BvMAaR18GuY7cCLMHjUjsl88NG3Xtf65DDAOIWXLmfiyGExwhbGpHfxErPbBGzcRLkebHL3xFnxqN3A%2FpglXe9abHg7QTmLCK%2FH3MRsXV%2F%2BZfxLAxMFf4g3Pz3IHnqBJAbyLy0vTj6Z99tiI5dNjb%2FNAkf8hjD3GI17lcgMh4sb2ziYMW7xVXCw6Y18XEMLbXxoDA07rNx96Ao5qCDsWV1kKrUPXDg4c8r0vDyOEPmugOeZZ5ASHdzfPSkrG8VlUXCGW8OJqJWn%2BkFg1WGD%2FPnLR3x8AZ0iMmLAD2FFPSKqVnuovPSaPern2juZ%2Frv7x8Qk%3D'}, {'domain': '.xyz.com', 'httpOnly': False, 'name': 's_sq', 'path': '/', 'secure': False, 'value': '%5B%5BB%5D%5D'}, {'domain': '.xyz.com', 'expiry': 1566918377, 'httpOnly': False, 'name': 's_nr', 'path': '/', 'secure': False, 'value': '1564326377171-New'}, {'domain': '.xyz.com', 'expiry': 1595862377, 'httpOnly': False, 'name': 'utag_main', 'path': '/', 'secure': True, 'value': 'v_id:016c391e09c700a1aed48730c1400308000230780086e$_sn:1$_se:3$_ss:0$_st:1564328177149$ses_id:1564326365646%3Bexp-session$_pn:2%3Bexp-session$vapi_domain:xyz.com'}, {'domain': '.xyz.com', 'expiry': 1627571171, 'httpOnly': False, 'name': 'mbox', 'path': '/', 'secure': False, 'value': 'session#4c9487152bb84ef2987d73d543089fa5#1564328226|PC#4c9487152bb84ef2987d73d543089fa5.17_214#1627571171'}, {'domain': '.xyz.com', 'httpOnly': False, 'name': 's_ppv', 'path': '/', 'secure': False, 'value': 'xyz%253Aus%253Aen%253Alasso%253Alogin%2C49%2C41%2C731'}, {'domain': '.xyz.com', 'expiry': 1658934377, 'httpOnly': False, 'name': 'dayssincevisit', 'path': '/', 'secure': False, 'value': '1564326377174'}, {'domain': '.xyz.com', 'httpOnly': False, 'name': 's_tp', 'path': '/', 'secure': False, 'value': '1482'}, {'domain': '.xyz.com', 'expiry': 1627484766, 'httpOnly': False, 'name': 'AMCV_036784BD57A8BB277F000101%40AdobeOrg', 'path': '/', 'secure': False, 'value': '-715282455%7CMCIDTS%7C18106%7CMCMID%7C03208673074170701752888429663373851045%7CMCAAMLH-1564931166%7C7%7CMCAAMB-1564931166%7C6G1ynYcLPuiQxYZrsz_pkqfLG9yMXBpb2zX5dvJdYQJzPXImdj0y%7CMCOPTOUT-1564333566s%7CNONE%7CMCCIDH%7C991685359%7CMCSYNCSOP%7C411-18113%7CvVersion%7C4.2.0'}, {'domain': '.xyz.com', 'expiry': 1564328177, 'httpOnly': False, 'name': 's_invisit', 'path': '/', 'secure': False, 'value': 'true'}, {'domain': '.xyz.com', 'expiry': 1574694377, 'httpOnly': False, 'name': 'aam_cms', 'path': '/', 'secure': False, 'value': 'segments%3D15025641%7C9625302'}, {'domain': '.xyz.com', 'expiry': 1572102377, 'httpOnly': False, 'name': '_fbp', 'path': '/', 'secure': False, 'value': 'fb.1.1564326367342.1042808311'}, {'domain': '.xyz.com', 'expiry': 1564632000, 'httpOnly': False, 'name': 's_vnum', 'path': '/', 'secure': False, 'value': '1564632000293%26vn%3D1'}, {'domain': '.xyz.com', 'expiry': 1595862373, 'httpOnly': False, 'name': 'gig_hasGmid', 'path': '/', 'secure': False, 'value': 'ver2'}, {'domain': '.xyz.com', 'expiry': 1564328177, 'httpOnly': False, 'name': 'dayssincevisit_s', 'path': '/', 'secure': False, 'value': 'First%20Visit'}, {'domain': '.xyz.com', 'httpOnly': False, 'name': 'AMCVS_036784BD57A8BB277F000101%40AdobeOrg', 'path': '/', 'secure': False, 'value': '1'}, {'domain': '.xyz.com', 'expiry': 1572102377, 'httpOnly': False, 'name': '_gcl_au', 'path': '/', 'secure': False, 'value': '1.1.195383222.1564326367'}, {'domain': '.xyz.com', 'httpOnly': False, 'name': 'check', 'path': '/', 'secure': False, 'value': 'true'}, {'domain': 'www.apps.xyz.com', 'httpOnly': True, 'name': '', 'path': '/ebilling', 'secure': False, 'value': 'Secure'}, {'domain': '.xyz.com', 'expiry': 1627398370.11634, 'httpOnly': True, 'name': 'xyz_language_preference', 'path': '/', 'secure': True, 'value': 'en_US'}, {'domain': '.xyz.com', 'expiry': 1574694377, 'httpOnly': False, 'name': 'aam_uuid', 'path': '/', 'secure': True, 'value': '03481510196229088272932637092714926177'}, {'domain': '.xyz.com', 'httpOnly': False, 'name': 's_cc', 'path': '/', 'secure': False, 'value': 'true'}, {'domain': '.xyz.com', 'httpOnly': True, 'name': 'sharedsession', 'path': '/', 'secure': True, 'value': 'c3858d5f-7419-44ff-a2cb-e7dc273186e2:m'}, {'domain': '.xyz.com', 'expiry': 1564328230, 'httpOnly': False, 'name': 'mboxEdgeCluster', 'path': '/', 'secure': False, 'value': '17'}] below is what I have so far driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", options=opts) # tried find element by name and clicking - no luck # driver.find_element_by_name("tNumber").click() # driver.find_element_by_name("tNumber").clear() # driver.find_element_by_name("tNumber").send_keys(tnumber) # driver.find_element_by_id("request_0").click() #---------------------------------------------- # tried moving to the element and clicking -- no luck # submit = driver.find_element_by_id("requestGSR_0") # action = webdriver.common.action_chains.ActionChains(driver) # action.move_to_element_with_offset(submit, 1, 1) # action.click() # action.perform() #---------------------------------------------- # tried the method below and does not work action1 = ActionChains(driver) tnumber_input = driver.find_element_by_name('tNumber') action1.move_to_element(tnumber_input).perform() action1.click(tnumber_input).perform() action1.send_keys_to_element(tnumber_input,tnumber).perform() action2 = ActionChains(driver) submit_button = driver.find_element_by_id('request_0') action2.move_to_element(submit_button).perform() action2.click(submit_button).perform()I would like to be able to use webdriver to submit the "request" form and get to the right page (without the error message). RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - NSearch - Jul-29-2019 Have I provided all information that would be helpful to get assistance with this issue? RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - Larz60+ - Jul-30-2019 It would be better to explain what the goal is, and the steps you perceive needed to get there. I don't think you should have a need to write any javascript at all, and should be able to do it all with python. RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - NSearch - Jul-30-2019 Larz60+, thank you very much for responding -- I was beginning to believe my posts were not visible! My goal is relatively simple or should be. I want to click this button: Quote:<input type="submit" value="Submit" id="request_0" class="bSwan"> When I click it using the different methods in python, the form below submits, but takes me to a screen that shows an error: Quote:<form id="request" name="request" onsubmit="return checkAndSubmit(this.tNumber.value)" action="/ebilling/request.action" method="post"> When I do the exact same thing manually, by moving my mouse and clicking it, I do not get the error and the page processes as it should. Thank you again for your help RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - metulburr - Jul-30-2019 (Jul-30-2019, 12:43 PM)NSearch Wrote: but takes me to a screen that shows an error:What is the error? You dont have any waiting methods. A common error is the program goes too fast for the internet speed can load the page. RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - NSearch - Jul-30-2019 This is what is displayed: Quote:Error Message I have a wait, performed this way: submit = driver.find_element_by_id("request_0") action = webdriver.common.action_chains.ActionChains(driver) action.move_to_element_with_offset(submit, 1, 1) action.click_and_hold(submit).perform() time.sleep(.5) action.release(submit).perform() RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - metulburr - Jul-30-2019 why cant you just simply do submit.click() after submit is created?submit = driver.find_element_by_id("request_0") submit.click() RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - NSearch - Jul-30-2019 Hi metulburr, Did you read my post? I have tried that a variety of ways and .click() does not work. RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - metulburr - Jul-30-2019 Sorry my fault. Is there any way we can view your full code with access to this webpage and the element you are having trouble with? Or is that not possible? (Jul-30-2019, 12:43 PM)NSearch Wrote: When I do the exact same thing manuallyIs this manually in the selenium browser or your own? Are you passing any cookies beforehand? import requests from selenium import webdriver driver = webdriver.Firefox() url = "some_url" #a redirect to a login page occurs driver.get(url) #storing the cookies generated by the browser request_cookies_browser = driver.get_cookies() #making a persistent connection using the requests library params = {'os_username':'username', 'os_password':'password'} s = requests.Session() #passing the cookies generated from the browser to the session c = [s.cookies.set(c['name'], c['value']) for c in request_cookies_browser] resp = s.post(url, params) #I get a 200 status_code #passing the cookie of the response to the browser dict_resp_cookies = resp.cookies.get_dict() response_cookies_browser = [{'name':name, 'value':value} for name, value in dict_resp_cookies.items()] c = [driver.add_cookie(c) for c in response_cookies_browser] #the browser now contains the cookies generated from the authentication driver.get(url) #now find and press your button RE: Python Selenium .click() Loads Error - Works Manually.- Events not Triggered - NSearch - Jul-30-2019 Thank you for the response metulburr! It's really not possible to view the full code because it contains username/password info. I posted about everything I know to post as far as what is included on the webpage itself, but I would be glad to provide more information if needed. Quote:When I do the exact same thing manually The page performs as expected when I navigate to the site and click the button manually OR when I have selenium navigate to the page and I click the button manually. I get the error message whenever I use any programmatic method of clicking the button in question. Quote:Are you passing any cookies beforehand? No, I haven't tried passing cookies before hand. I am reviewing your code now to see if I can make sense of it. Thanks again for your response. |