AI123 Posted December 12, 2020 Share Posted December 12, 2020 (edited) Hello, on a website with the source code I attached I tried to press the "Einverstanden" button automatically. But I always get the message "Unable to locate element" These are my three different attempts to click on the "Einverstanden" button: ;Full XPath: /html/body/div/div[2]/div/div/div[2]/div/div/button ;Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//html/body/div/div[2]/div/div/div[2]/div/div/button\"}\n Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/div/div[2]/div/div/div[2]/div/div/button") ;XPath: //*[@id="onetrust-accept-btn-handler"] ;Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//*[@id='onetrust-accept-btn-handler']\"} Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='onetrust-accept-btn-handler']") ;Test: ;Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//button[@id='onetrust-accept-btn-handler']\"} ;Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='onetrust-accept-btn-handler']") _WD_ElementAction($sSession, $sElement, 'click') This is the source code of the website: So what can be wrong and what have I to do to click on the "Einverstanden" button automatically? Edited December 12, 2020 by AI123 Link to comment Share on other sites More sharing options...
Danp2 Posted December 12, 2020 Share Posted December 12, 2020 The element is inside an iframe. You need to switch to the correct context using _WD_Window or_WD_FrameEnter before searching for the element. AI123 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AI123 Posted December 12, 2020 Author Share Posted December 12, 2020 (edited) I tried now this: Local $sFrame = _WD_FrameEnter($sSession, "//*[@id='sprd-consent'") ; and tried this Local $sFrame = _WD_FrameEnter($sSession, "sprd-consent") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='onetrust-accept-btn-handler']") _WD_FrameLeave($sSession) But it seems the frame can't be found: _WD_Navigate: {"value":null} __WD_Post: URL=HTTP://127.0.0.1:9515/session/be5083e04509054e7b4a5f77e5375431/frame; $sData={"id":{"element-6066-11e4-a52e-4f735466cecf":"//*[@id='sprd-consent'"}} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n (Ses... If I imagine right there is a website where all _WD_ function parameters are described. But now I only can find this. https://www.autoitscript.com/wiki/WebDriver. But there the function parameter are not described. So can you or someone please say me where I can find the website where _WD_ functions and parameters are described? Update: Have found it. Parameters are described at the bottom of the https://github.com/Danp2/WebDriver page. So could it be I use a wrong parameter in _WD_FrameEnter? Edited December 12, 2020 by AI123 Link to comment Share on other sites More sharing options...
Nine Posted December 12, 2020 Share Posted December 12, 2020 Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='sprd-consent']") _WD_FrameEnter($sSession, $sElement) Try this AI123 and Danp2 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
AI123 Posted December 12, 2020 Author Share Posted December 12, 2020 5 minutes ago, Nine said: Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='sprd-consent']") _WD_FrameEnter($sSession, $sElement) Try this That worked, thank you. :) Link to comment Share on other sites More sharing options...
AI123 Posted December 12, 2020 Author Share Posted December 12, 2020 1 hour ago, Danp2 said: The element is inside an iframe. You need to switch to the correct context using _WD_Window or_WD_FrameEnter before searching for the element. Thank you. 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