# 4.6 Handling frames

Below is the code snippet to interact with frames using selenium webdriver.

```
@Test
    public void testMethod() {

        WebDriver driver = new FirefoxDriver();
        // URLs to be verified..
        String expectedresult[] = { "Google","W3Schools Online Web Tutorials","Sparsh", "Delicious" };

        int count = 0;
        // We are fetching all the values in dropdown below and clicking one by one
        driver.findElement(By.xpath("/someXpath/to/dropdownLinks")).click();

        // Here we switch to newly opened frame
        driver.switchTo().frame("frameName");

        //Perform actions in this frame
        System.out.println(driver.getTitle());    

        // Switch back to the window
        driver.switchTo().defaultContent();
    }
```

Also remember you cannot switch between multiple frames.If in case there are three cascaded level of frames then you have to first switch back to default content and then switch to the next frame otherwise you may get NoSuchElementException.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://n-saikiran.gitbook.io/selenium-2-web-driver-basics/4.-selenium-prospects/4.6-handling-frames.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
