Skip to content
Advertisement

Reach for the deep nested element using Selenium WebDriver (Java)

I looked through a lot of topics on Stackoverflow and tried several recommendations but could hardly succeed in resolving my particular case. I’m trying to automate Google Cloud Pricing Calculator using Selenium WebDriver + Java. I need insert the Number of instances (the first input area on the page) using Java code.

My Java code is following:

JavaScript

But NoSuchElementException is thrown when I launch the code: “no such element: Unable to locate element: {“method”:”xpath”,”selector”:”//iframe[@id=’myFrame’]”}.

Xpath is correct but this element is hidden deep into html tree. How can I reach for the element (Number of instances) in this particular case? Thank you in advance!

Advertisement

Answer

You first need to switch to the parent iframe element, then switch into the inner iframe and only after that try accessing the input element.
I see you tried to locate the iframe elements but you do not switch into them.
Try this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement