Handling Iframes In Selenium (Java)

Handling Iframes In Selenium (Java)

Often Website will use Iframes to contain some elements in a way which makes finding said elements difficult in a Selenium test. To switch the drivers focus to an Iframe you need to use driver.switchTo().frame(identifier) where the identifier is either the index, name or ID of the iframe.

To show this in an example here is a code snippet:

driver.switchTo().frame(1);

//This element is not visible unless the iframe is in focus
driver.findElement(By.xpath("//select[@id='tCounty']"));

Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.