aircooled Posted September 21, 2019 Share Posted September 21, 2019 I am new to Javascript have googled and can't solve this problem, need help. Have automated several flows in websites without problems but in this specific site I can't even get the uid/pwd fields or the login button to react to Javascript. Here what I tried for the uid field document.getElementsByClassName("inline")[1].value := "Mary" document.getElementsByClassName("inline")[0].value := "Mary" document.getElementsByName("USERNAME.DUMMY.DUMMY.1")[0].value := "Mary" document.getElementsByName("USERNAME.DUMMY.DUMMY.1")[1].value := "Mary" document.getElementById("namedata").value := "Mary" The same for the pwd field to no avail. With a Selenium framework there is no problem to insert data in the fields and click to the Login button and repository objects are created with attributes name and id. Can't understand why using the same attributes Java script can't access the fields or the button. Here the attributes retrieved by the Selenium Framework. https://postimg.cc/DWBrxGxP I inspect that specific element with Chrome's DevTools and use the class/name/id there or choose "Copy selector" in its context menu and use document.Queryselector. No success at all. Here the complete HTML code of the page. What is going on, why can't I in this specific site write to uid and /or pwd fields? <!DOCTYPE html> <html><!-- Arhettan Startup Screen --><head> <meta http-equiv="content-type" content="text/html; charset=windows-1252"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="CACHE-CONTROL" content="no-cache"> <meta http-equiv="Expires" content="0"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Arhettan On The Web</title> <style type="text/css"> HTML,BODY { /* The styles on the body element here prevent IE form showing a greyed-out vertical scroll bar on the browser window at all times. */ width: 100%; height: 100%; overflow: auto; } IFRAME { width: 100%; height: 100%; position: absolute; } </style> <script type="text/javascript"> var appBodyClassName="SKINNED"; var newlogincss = '../../kmdnatrium/login_kmd1.css'; var customBranding = {'welcomeURL':'../../kmdnatrium/kmdnatrium.html'}; var newloginhtml = '<img src="../../kmdnatrium/images/login/Login_background_kmd.jpg" class="bg"><div align=center valign=middle class="login-center-transparent">\ <div class="login-top-left">\ <div class="container">\ <span class="password"><div class="inline" id="usernametext"></div> </span><div class="inline" id="namedata"><X-SUBST type="text" name="USERNAME.DUMMY.DUMMY" class="form" autocomplete="Off"></X-SUBST></div>\ <br>\ <span class="password"><div class="inline" id="pwdtext"></div> </span><div class="inline" id="pwddata"><X-SUBST type="text" name="PASSWORD.DUMMY.DUMMY" class="form" autocomplete="Off"></X-SUBST></div>\ <br>\ <span>\ <div class="rememberme">\ <div class="inline" id="remembertext"></div>\ <div class="inline" id="rememberdata"><X-SUBST type="checkbox" name="REMEMBER_ME.DUMMY.DUMMY" autocomplete="Off"></X-SUBST></div> \ </div>\ <div class="loginbutton" id="submitdata">\ <X-SUBST type="text" name="ATTEMPT.DUMMY.DUMMY" class="form"></X-SUBST>\ <X-SUBST type="submit" name="LOGIN.DUMMY.DUMMY" src="../../generic/images/login/Logo_for_phase_1_kmd.jpeg"><INPUT type="submit" name="LOGIN.DUMMY.DUMMY" value="Click Here to Login"></X-SUBST>\ </div>\ </span>\ </div>\ </div>\ <div class="login-top-right">\ <div class="img">\ </div>\ </div>\ <div class="login-bottom">\ <div id="MESSAGEBOARD"></div>\ <div id="loginLinkContainer" style="float:left">\ </div>\ <div class="login-bottom-info">\ +45 44 605 722 <b>|</b> <a href="mailto:natriumsupport@kmd.tu">natriumsupport@kmd.tu</a> <b>|</b> <a href="www.kmd.tu">www.kmd.tu</a>\ </div>\ <div class="login-version-text" id="versiontext"></div>\ </div>\ </div>'; if(top != window){ top.location = window.location.href; } function getWindowState(){var g=this,f={scrollLeft:NaN,scrollTop:NaN},j={clientWidth:NaN,clientHeight:NaN},k={innerWidth:NaN,innerHeight:NaN},l='scrollLeft',m='scrollTop',n=0,p,q,r,s,u=null,v=null, o={getScrollX:x,getScrollY:y,getWidth:function(){return I('getWidth');},getHeight:function(){return I('getHeight');}};function X(){J();return x();}function Y(){J();return q;}function x(){return f[l]|0;}function y(){return f[m]|0;}function W(){return k.innerWidth;}function w(){return j.clientWidth;}function H(){return k.innerHeight;}function h(){return j.clientHeight;}function U(){return(F()?o.getHeight:h)();}function V(){return (F()?o.getWidth:w)();}function D(){o.getWidth=W;o.getHeight=H;}function E(){o.getScrollX=x;o.getScrollY=y;}function F(){if((s!=(s=H()))||(r!=(r=W()))){R();return true;}return false;}function J(){if((q!=(q=y()))||(p!=(p=x()))){R();}}function K(a,b){var V,H;if(((V=(g.innerHeight-a.clientHeight))>=0)&&((H=(g.innerWidth-a.clientWidth))>=0)&&(!(x()&&!V))&&(!(y()&&!H))&&(!((H&&(b.h||(b.h=H))&&(H!=b.h))||(V&&(b.v||(b.v=V))&&(V!=b.v))))){if(H==V){b.r=(+Boolean(H));}else if((H&&!V)||(V&&!H)){b.r=(H+V);}else{b.r=NaN;}}else{b.r=NaN;}return b;}function P(t){for(var c=arguments.length;--c;){if(typeof t[arguments[c]]!='number'){return false;}}return true;}function Q(a,b){if(a&&P(a,'clientWidth','clientHeight')){K(a,b);}return b;}function I(c){r=W();s=H();q=y();p=x();u={v:0,h:0,r:NaN};v={v:0,h:0,r:NaN};o.getWidth=V;o.getHeight=U;o.getScrollX=X;o.getScrollY=Y;R();Q=K;return o[c]();}function R(){var c=document,b=isNaN(Q(c.body,u).r),d=isNaN(Q(c.documentElement,v).r);if(b||d){if(b&&d){E();D();}else{j=((d)?c.body:c.documentElement);u=((d)?u:v);v=null;R=T;}}else{j=((u.r < v.r)?c.body:c.documentElement);}}function T(){if(isNaN(Q(j,u).r)){u=null;E();D();}else if((u.v)&&(u.h)&&(++n > 2)){u=null;o.getWidth=w;o.getHeight=h;E();}}if(!P(g,'innerHeight','innerWidth')){j=compatModeTest(j);o.getWidth=w;o.getHeight=h;}else{k=g;}if(P(g,'pageYOffset','pageXOffset')){f=g;m='pageYOffset';l='pageXOffset';}else{f=compatModeTest(f);}return(getWindowState=function(){return o;})();} function compatModeTest(o){var d=document;if((d.compatMode)&&(d.compatMode.indexOf('CSS')!=-1)&&(d.documentElement)){return (compatModeTest=function(){return d.documentElement;})((o=null));}else if(d.body){return (compatModeTest=function(){return d.body;})((o=null));}else{return o;}} </script> </head> <body topmargin="0" marginwidth="0" marginheight="0" leftmargin="0"> <div style="position: absolute; bottom: 0px; background-color: #888888; width: 100%; padding: 0px; margin: 0px;"> <select id="messageBox" style="width: 100%; padding: 0px; margin: 0px; border: 0px none #888888;"> <option selected="selected"></option> <option></option> <option></option> <option></option> </select> </div> <script language="JAVASCRIPT" src="natriumkmd_files/Arhettan.js"></script><iframe name="application" id="application" marginheight="0" marginwidth="0" src="natriumkmd_files/SPDEMLOGIN.htm" width="100%" height="100%" frameborder="0"></iframe> </body></html> Any help will be highly appreciated thanks in advance. Link to comment Share on other sites More sharing options...
dsonesuk Posted September 21, 2019 Share Posted September 21, 2019 Javascript does not use ':=' to apply a value, only '='. Link to comment Share on other sites More sharing options...
aircooled Posted September 21, 2019 Author Share Posted September 21, 2019 It works perfect with ':=' on the sites I succeeded with. I am calling Java script from other software could be that. But it works. Link to comment Share on other sites More sharing options...
Funce Posted September 22, 2019 Share Posted September 22, 2019 On 9/22/2019 at 2:25 AM, aircooled said: It works perfect with ':=' on the sites I succeeded with. I am calling Java script from other software could be that. But it works. := is invalid JavaScript. Uncaught SyntaxError: Unexpected token : Link to comment Share on other sites More sharing options...
aircooled Posted September 23, 2019 Author Share Posted September 23, 2019 The problem here is that I SUCCEED inserting in some websites and with the same login not in others. In Chrome console it requires := but executing from another very special software at my work it accepts both. Forget about "=" or ":=" in the sites i fail to update it works with neither. In the sites that I SUCCEED I do it with both from my software and only with ":=" in Chrome Console. Please read the source code in my first message and help me with a command to populate the uid field as well as the pwd field. Thank you very much. Link to comment Share on other sites More sharing options...
smus Posted September 23, 2019 Share Posted September 23, 2019 := looks like it is taken from Delphi code Link to comment Share on other sites More sharing options...
vmars316 Posted September 23, 2019 Share Posted September 23, 2019 https://unminify.com/ Link to comment Share on other sites More sharing options...
aircooled Posted September 26, 2019 Author Share Posted September 26, 2019 (edited) I have found the solution. The field was inside a frame and now it works fine in Chrome Console. var iframevar = document.getElementById("application") var innerDoc = iframevar.contentDocument || iframe.contentWindow.document innerDoc.getElementById("USERNAME.DUMMY.DUMMY").value = "hello" However I cannot make it to work from my calling environment. Is there a way to consolidate the 3 lines above to 1 line? PS: I am calling JavaScript from AutoHotKey. It doesn't work in AHK I suspect because lines are executed before the prior line is completed. What is the easieast way to wait until a command is completed before continuing? Edited September 26, 2019 by aircooled Link to comment Share on other sites More sharing options...
dsonesuk Posted September 26, 2019 Share Posted September 26, 2019 Should it not be var iframevar = document.getElementById("application"); var innerDoc = iframevar.contentDocument || iframevar.contentWindow.document; innerDoc.getElementById("USERNAME.DUMMY.DUMMY").value = "hello"; Notice variable reference after OR '||' . Also Do you actually have an Element with a id of "USERNAME.DUMMY.DUMMY"? all I see is name attribute with this value Link to comment Share on other sites More sharing options...
aircooled Posted September 26, 2019 Author Share Posted September 26, 2019 You are totally correct, dsonesuk it should be || iframevar Funny thing is it works fine with iframe in Chrome console. Could be that it retrieves from iframevar.contentDocument and ignores iframe.contentWindow.document (wrong) However. Added semicolons and corrected iframe -> iframevar and it doesn't work from AutoHotKey while it continues to work fine from Chrome Console I have converted to a oneliner that works in console (which proves why it worked with iframe iso iframevar) but not from AutoHotKey: document.getElementById("application").contentDocument.getElementById("USERNAME.DUMMY.DUMMY").value = "Hello" Link to comment Share on other sites More sharing options...
dsonesuk Posted September 26, 2019 Share Posted September 26, 2019 (edited) The code after the variable are browser specific, if it is not supported for one it will use the other. DID YOU ADD, OR DID THE ELEMENT WITH name="USERNAME.DUMMY.DUMMY" have id="USERNAME.DUMMY.DUMMY" Edited September 26, 2019 by dsonesuk Link to comment Share on other sites More sharing options...
aircooled Posted September 27, 2019 Author Share Posted September 27, 2019 (edited) 8 hours ago, dsonesuk said: The code after the variable are browser specific, if it is not supported for one it will use the other. DID YOU ADD, OR DID THE ELEMENT WITH name="USERNAME.DUMMY.DUMMY" have id="USERNAME.DUMMY.DUMMY" Thanks dsonesuk. 1) Could you please clarify which code you refer to that is browser specific and what problem it implies for implementing in AHK.. 2)THE ELEMENT WITH name="USERNAME.DUMMY.DUMMY" has id="USERNAME.DUMMY.DUMMY" I have not changed or added anything. Edited September 27, 2019 by aircooled Link to comment Share on other sites More sharing options...
dsonesuk Posted September 27, 2019 Share Posted September 27, 2019 (edited) Some browers will use the .contentDocument Others contentWindow.document The browser will have fallback to use one OR the other depending if it is supported for that browser. innerDoc Will then equal the browser supported option to use from that point and onwards. The reason your code worked with the second condition having the wrong variable name, was because the first one was supported so it ignored the incorrect variable alternative. It would have been a problem if the browser did not support the first and attempted to use second, resulting in undefined error. Edited September 27, 2019 by dsonesuk Link to comment Share on other sites More sharing options...
aircooled Posted October 1, 2019 Author Share Posted October 1, 2019 This statement solved the problem: ie.document.getElementById("application").contentDocument.getElementById("USERNAME.DUMMY.DUMMY").value := "Mary" 😍 😍 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now