Python Forum
Python Selenium .click() Loads Error - Works Manually.- Events not Triggered
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Selenium .click() Loads Error - Works Manually.- Events not Triggered
#1
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<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>&nbsp;</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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
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">&nbsp;&nbsp;'+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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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).
Reply
#2
Have I provided all information that would be helpful to get assistance with this issue?
Reply
#3
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.
Reply
#4
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
Reply
#5
(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.
Recommended Tutorials:
Reply
#6
This is what is displayed:

Quote:Error Message
A system error has been encountered.
To try again, you may click back button or log out.
If the problem persists, please contact your system administrator.

I have a wait, performed this way:

1
2
3
4
5
6
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()
Reply
#7
why cant you just simply do submit.click() after submit is created?

1
2
submit = driver.find_element_by_id("request_0")
submit.click()
Recommended Tutorials:
Reply
#8
Hi metulburr,

Did you read my post? I have tried that a variety of ways and .click() does not work.
Reply
#9
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 manually
Is this manually in the selenium browser or your own?

Are you passing any cookies beforehand?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
Recommended Tutorials:
Reply
#10
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
Is this manually in the selenium browser or your own?

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium - Error writing in field brunox96 1 1,407 Nov-22-2024, 03:28 PM
Last Post: andraee
  Click on a button on web page using Selenium Pavel_47 7 7,108 Jan-05-2023, 04:20 AM
Last Post: ellapurnellrt
  Show HTML in Python application and handle click SamHobbs 2 3,836 Sep-28-2021, 06:27 PM
Last Post: SamHobbs
  Selenium/Helium loads up a blank web page firaki12345 0 2,701 Mar-23-2021, 11:51 AM
Last Post: firaki12345
  button click error rafarangel 2 3,934 Feb-11-2021, 08:19 PM
Last Post: buran
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 4,843 Jun-07-2020, 04:42 PM
Last Post: samlee916
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 2,469 May-02-2020, 11:21 AM
Last Post: rajeev1729
  selenium click in iframe fails 3Pinter 6 7,402 Apr-29-2020, 12:59 PM
Last Post: Larz60+
  Selenium weird error julio2000 0 2,240 Feb-23-2020, 01:24 PM
Last Post: julio2000
  Selenium webdriver error WiPi 4 15,204 Feb-09-2020, 11:38 AM
Last Post: WiPi

Forum Jump:

User Panel Messages

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