Switching between frames(also known as iframes) is possible by using driver.switchTo().frame() method in selenium. There is different options available such as index, name, id or web element to switch between frames. Following are the examples given below for switching between frames:
By using index:
Switching between frames can be done by passing zero based index to the frame in selenium. Following is the example code given below for switching frames using index:
Example code:
driver.switchTo().frame(index); //index such as 0, 1 etc.,
By using Name or ID:
Name or ID can be passed to frame for switching in selenium. Following is the example code given below for switching frame using name or id.
Example code:
driver.switchTo().frame(framename OR frameid);
By using Webelement:
Switching between frames can be possible by passing web element to frame. Following is the example code given below to switch between frames using selenium
Example code:
WebElement elem = driver.findElement(By.id(“country”));
driver.switchTo().frame(elem);