How to use 'Chrome DevTools' to find iframe locator(s):

How to use ‘Chrome DevTools’ to find iframe locator(s):

  1. Use Chrome to navigate to this iframe example: <iframe>: The Inline Frame element - HTML: HyperText Markup Language | MDN
  2. Press F12 to open ‘Chrome DevTools’.
  3. Click on the ‘Console’ tab and input document.querySelectorAll("iframe"), press Enter.
  4. Expand the Nodelist(2).
  5. Click on the second iframe result, the iframe is loaded.
  6. Right-click on the result, click ‘Copy’ > ‘Copy XPath’.
  7. Press ‘Ctrl+F’ and paste the result into the search field, press Enter.

Result: //*[@id="frame_a_simple_iframe"] is found on the page.
If more than one iframe result were to display you could use (//*[@id="frame_a_simple_iframe"])[1] or (//*[@id="frame_a_simple_iframe"])[2] and so on to pick the target iframe. Using (//iframe)[1] or (//iframe)[2] would also work. In this case (//iframe)[2] would be the locator to use. You could use (//iframe) to cycle through all iframes on the page.



Thank you for sharing such awesome tips

1 Like

Nice one!!

Great! smartly explained.

1 Like