Unable to find element in Selenium WebDriver By Name and XPath

前端 未结 1 1907
灰色年华
灰色年华 2020-12-07 03:41

I am working with Selenium WebDriver and wrote a small code to find and element (i.e a button) and click on it. Here is the HTML code for the button:



        
相关标签:
1条回答
  • 2020-12-07 04:05

    Since your element is in an IFrame, you'll need to 'switch' to that IFrameusing the WebDriver API.

    By default, Selenium will use the 'top' frame, and therefore any 'find element' queries will be directed to the most top frame, and ignore any child IFrames.

    To solve this, 'switching' to the current IFrame directs Selenium to shove any requests to that frame instead.

    driver.SwitchTo().Frame()

    Note that you'll need a way of accessing the frame, either by it's ID, index (the top frame is 0, next frame down is 1, etc...) or name.

    Another note is that any further requests will be directed to that IFrame, ignoring any others, which includes the top one...so if you need to access the top frame, you'll need to switch back:

    driver.Switch().DefaultContent().

    0 讨论(0)
提交回复
热议问题