AJB Posted August 24, 2015 Posted August 24, 2015 First off, I would like to thank everyone that contributes to this forum. I am new to autoit, and this forum has been a wealth of helpful knowledge and insight.My Issue:I've noticed a recurring issue when trying to write scripts to login, navigate through webpages, and download files. I am sure that it is caused by my bad scripting, but I couldn't find answers after scouring the forums and google searches. What seems to be happening, is that after I launch a webpage and then login, anytime I try to run new functions on consecutive webpages, autoit still references the source of the original login page as opposed to the current page. I would post the page here, but it is a private access site, so it doesn't really help, and I've had the issue on 3 of 4 websites.Some of the script:expandcollapse popup#include <IE.au3> #include <Date.au3> Call ("myFunction") Func myFunction() $oIE = _IECreate ("http://www.placeholder.com/login") Local $username = _IEGetObjByName ($oIE, "tbUserid") Local $password = _IEGetObjByName ($oIE, "tbPassword") Local $loginBtn = _IEGetObjByName ($oIE, "bLogin") _IEFormElementSetValue ($username, "myusername") _IEFormElementSetValue ($password, "mypassword") _IEAction($loginBtn, "click") Sleep(1000) ;finds and clicks link $oElements = _IETagNameAllGetCollection ($oIE) For $oElement In $oElements If $oElement.innerText = "Sample Button" Then _IEAction ( $oElement, "click" ) Next Sleep(1000) ;Finds and focuses on dropdown to make selection Local $oIE = _IEAttach("Filter by Location ", "text") $ddDocType = _IEGetObjByName($oIE, "rbDocType") $ddDocType.focus _IEFormElementOptionSelect($ddDocType, "Sample Selection Name", 1, "byText") Sleep(1000) ;click another button $oButtons = _IETagnameGetCollection($oIE, "input") For $oButton in $oButtons If String($oButton.value) = "ALL" Then _IEAction($oButton, "click") ExitLoop EndIf Next etc..... EndFuncFor clarity:In the above script, everything seems to be working fine, however, each time the page changes (e.g. after clicking the login button) the script will then fail, as it continues to reference the original page. For instance, if I run _IETagNameAllGetCollection and return the values in a msgbox, it returns the html tags of the original login page, rather than the post login landing page. What is curious, and what has me confused, is that I can declare a new variable using _IEAttach by scraping the text (which seems to read the current page, rather than the previous). I can then use IE get functions and they read the current page's html, enabling my script to work, but I have to do it for every page change. This seems cumbersome and incorrect, not to mention it creates new issues. Can someone please point out what I am doing wrong with this? I've tried reading through the documentation but I just can't seem to figure this out.Thank you.
Valuater Posted August 24, 2015 Posted August 24, 2015 I haven't done this in a while and am not able to test your script... But I suggest to change the local = $oIE to Local = $oIEA or another "new" variable name and throughout the use of that new variable name in this function... Also "Local" is not transferable throught a script. It's only use is inside that function... (without a return);Finds and focuses on dropdown to make selection Local $oIEa = _IEAttach("Filter by Location ", "text") $ddDocType = _IEGetObjByName($oIEa, "rbDocType") $ddDocType.focus _IEFormElementOptionSelect($ddDocType, "Sample Selection Name", 1, "byText") Sleep(1000)
AJB Posted August 26, 2015 Author Posted August 26, 2015 I've learned to just reattach to the updated page by looking for text, it just seems kind of dirty and convoluted to have to reattach every time there is a page change when there is only one instance of internet explorer running and with only one tab or page.I feel like this is the incorrect way of doing things, especially when Autoit reads the current page to find and attach by text, which means it sees the current iteration of the webpage when _IEAttach runs but other actions such as _IEGetObjById reference the last page or page iteration.Can someone chime in and let me know if my assumptions are wrong, or if this is the way it's supposed to work? Thank you for your assistance.
JohnOne Posted August 27, 2015 Posted August 27, 2015 Problem is, I doubt anyone else has this problem, I certainly don't. And since no-one can test on your mysterious website it's a little difficult to "chime in" with any worthwhile input.I suggest you write some reproducing code which uses some other website. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
rollyboo Posted September 11, 2015 Posted September 11, 2015 Were you able to find a solution to this issue? I'm also having the same problem, looks like AutoIt references to the first page, even if a completely new one has opened after login and there is only one instance of internet explorer running and with only one tab or page.
Yuji Posted September 11, 2015 Posted September 11, 2015 Try to use _IELoadWait($oIE). _IEFormElementSetValue ($username, "myusername") _IEFormElementSetValue ($password, "mypassword") _IEAction($loginBtn, "click") _IELoadWait($oIE) ;finds and clicks link $oElements = _IETagNameAllGetCollection ($oIE) For $oElement In $oElements If $oElement.innerText = "Sample Button" Then _IEAction ( $oElement, "click" ) Next Sleep(1000)
AJB Posted May 23, 2016 Author Posted May 23, 2016 Has anyone else run into this problem and found the solution? In older versions of autoit it doesn't happen, but anything I try to move over to or build using the current iteration of autoit has the same issue. The variable declared for an attached or created IE page references the original instance only, so if the webpage changes due to a button or link being followed, everything still references the original page and therefore breaks (e.g. when trying to find a link, button, input, etc since it "doesn't exist" on the current page state). This is an issue whether attaching via the window handle or through text on the page.
macro69 Posted June 27, 2019 Posted June 27, 2019 run into the same issue with intranet, just following up the thread and see if anyone comes up with a solution. thanks
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