# How to handle iFrames using Selenium Webdriver: switchTo()

**URL:** <https://forum.katalon.com/t/how-to-handle-iframes-using-selenium-webdriver-switchto/34915>\
**Category:** Tips and Tricks\
**Tags:** tips-tricks, katalon-studio\
**Created:** [October 18, 2019, 2:04pm UTC](https://forum.katalon.com/t/how-to-handle-iframes-using-selenium-webdriver-switchto/34915 "2019-10-18T14:04:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Evers](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dave_evers/32/435_2.png) [@Dave\_Evers](https://forum.katalon.com/u/Dave_Evers)\
**Post date:** [October 18, 2019, 2:04pm UTC](https://forum.katalon.com/t/how-to-handle-iframes-using-selenium-webdriver-switchto/34915/1 "2019-10-18T14:04:24Z")

</div>

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

```auto
//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

```

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@Timo\_Kuisma](https://forum.katalon.com/u/Timo_Kuisma)\
**Post date:** [October 18, 2019, 3:05pm UTC](https://forum.katalon.com/t/how-to-handle-iframes-using-selenium-webdriver-switchto/34915/2 "2019-10-18T15:05:31Z")

</div>

hello,

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