How to handle iFrames using Selenium Webdriver: switchTo()


#1

How to handle iFrames using Selenium Webdriver: switchTo()
See https://www.guru99.com/handling-iframes-selenium.html
I used “By Index” which worked for me.

//Add to the imports section for use with "driver.switchTo().frame(0)"
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

//Input the following anywhere in the body of your test case
WebUI.delay(5) //Sets time to wait for iframe to be visibile
WebDriver driver = DriverFactory.getWebDriver()
driver.switchTo().frame(0) // I only had 1 iframe to deal with

//When finished working in the iframe switch back to default content
WebUI.switchToDefaultContent

#2

hello,

why not clicking iframe locator to get it focus
if nested iframes then clicking in order