Auto_It_Hurts Posted January 6, 2023 Share Posted January 6, 2023 Hi all, First post so I have to say this a great community and these forums have gotten me through 95% of my task to convert an IE script to Edge. Thanks for being awesome. Besides a few weird things with getting the window handle and moving the window (sometimes it works, sometimes it doesn't) my script is mostly working as intended now. The very last thing preventing the script from running like it used to is a check for the "busy" property of IE. Previously this was handled with: While _IEPropertyGet($oIE,"busy") = True Sleep(10) Can anyone please point me to some sort of reference that shows how to achieve something similar using Edge and WebDriver? Essentially it just lets the script keep moving as soon as the website loading spinner disappears so I could probably work around this with a bigger sleep timer after the click but this script iterates many times so this could cause the end result to be significantly slower. Any help you can provide would be greatly appreciated! Thanks! Link to comment Share on other sites More sharing options...
Danp2 Posted January 6, 2023 Share Posted January 6, 2023 Have you tried using _WD_LoadWait? P.S. Welcome to the forum! Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Auto_It_Hurts Posted January 8, 2023 Author Share Posted January 8, 2023 Thanks Danp2, that's exactly what I was looking for. Unfortunately, it's not playing nice with the site I'm trying to integrate with. This function seems to be returning "success" while the loading icon is still displayed. I'm no HTML expert but I think I've located the DIV that the loading icon appears in. Is there maybe some way to check if a certain DIV is visible or not? Link to comment Share on other sites More sharing options...
Danp2 Posted January 9, 2023 Share Posted January 9, 2023 @Auto_It_HurtsTake a look at _WD_WaitElement and the $iOptions parameter. If you specify one of the available options ($_WD_OPTION_Hidden or $_WD_OPTION_NoMatch are the likely targets), then it should loop until the element meets that condition. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Auto_It_Hurts Posted January 10, 2023 Author Share Posted January 10, 2023 (edited) Thanks again for your help, Danp2. You're the true MVP. I did some experimenting with the _WD_WaitElement function as suggested but I'm hitting some roadblocks (likely caused by my poor HTML knowledge). I was mostly getting timeout returns from the WaitElement function except for using $iOption 8 (not found) and after getting a No Match error in _WD_FindElement I figured my error must be in how I'm addressing the actual element. I'm trying to address the element using XPATH. I found this post explaining that my problem was because the element I'm selecting is inside a frame: AutoIt Forum - XPath can't be found. This all makes perfect sense to me but the part that's breaking my brain is that the answer that fixed it was selecting the frame on the line AFTER attempting to find the element via XPATH. My understanding is that the first line selecting the element will not find the element because the script has not yet called the _WD_FrameEnter function. So, my question is what is the "best practice" for this situation? My guess would be something like the following: Local $sTargetFrame = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//frame[@name='nameOfFrame']") _WD_FrameEnter($sSession, $sTargetFrame) Local $sTargetElement = _WD_FindElement($SessionID, $_WD_LOCATOR_ByXPath, '//div[@id="idOfDivThatIWant"]') However, this seems to contradict what I saw in the above linked post where the solution seemed to be using _WD_FrameEnter AFTER attempting to select the DIV that's inside the frame. Hopefully this all makes sense. I'm no stranger to coding but HTML and I have never gotten along. UPDATE: I've attempted to use my guess as above and the _WD_FindElement targeting the frame is also saying element not found. I'm wondering if this is because the frame is nested. The frame I am targeting exists in a frameset that is nested in another frameset that is nested in an iframe. The iframe is nested in a div that is nested in a div in the body. Do I need to repeat lines as above starting from the top layer and basically keep targeting the frame of the next level down until I get to the element I need? Edited January 10, 2023 by Auto_It_Hurts Link to comment Share on other sites More sharing options...
Danp2 Posted January 10, 2023 Share Posted January 10, 2023 Yes, you need to be in the correct frame before the element can be accessed. See the DemoFrames example in wd_demo.au3 for how this can be done using multiple as well as single commands. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Auto_It_Hurts Posted January 13, 2023 Author Share Posted January 13, 2023 OK good news, after digging into the mess of frames I was able to select the DIV containing the loading image. I was then able to have the script pause successfully using the _WD_WaitElement. Thanks again Danp2! One thing I have noticed is the behaviour of this function can be a little bit erratic. For the most part it works as intended but occasionally it will seemingly pass this function despite the loading icon still being visible or get stuck waiting for the loading icon to disappear when it's already disappeared. I've played with the timeout option for _WD_WaitElement so it doesn't really matter if it gets stuck waiting because it will eventually pass but if it allows the script to continue while the loading icon is visible it causes a snowball effect that will stop the script entirely. So my last question (hopefully :P) is can I manually check the visibility of this element now that I have been able to locate it? I'm hoping I can supplement the existing function with some additional checks to guarantee the loading has finished before the script proceeds. I've created a variable to hold the DIV that only appears when loading and set it using _WD_FindElement but I'm having trouble figuring out correct usage of _WD_ElementAction to check if the display attribute is "none" or "block". Link to comment Share on other sites More sharing options...
Danp2 Posted January 13, 2023 Share Posted January 13, 2023 The following line comes directly from the existing _WD_WaitElement code -- $bIsVisible = _WD_ElementAction($sSession, $sElement, 'displayed') so you should be able to do the same in your script using the result from _WD_WaitElement or _WD_FindElement. P.S. It would be great if you could replicate the issue you described above using a website that we can all access. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Auto_It_Hurts Posted January 13, 2023 Author Share Posted January 13, 2023 Unfortunately, I can't share the webpage I am working on sorry. I will have a play on the weekend to see if I can find a public website to try and replicate this behaviour. Does anybody have a suggestion for a frame heavy website that uses a hidden element that appears while loading content after clicking a link? I think to replicate it will need to be something that doesn't navigate away from the page but loads different content in a frame after interacting. On the other hand, the above snippet might help me dig into the actual cause and, if so, I will report back here. 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