harshufrenz
harshufrenz

Reputation: 37

Unable to switch between frames

I am using this code:

    WebDriver driver = new FirefoxDriver();

    driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index");
    driver.switchTo().frame("classFrame");
    driver.findElement(By.linkText("com.thoughtworks.selenium")).click();
    System.out.println("The expected link is opened in the browser...");

    driver.switchTo().frame(driver.findElement(By.name("packageListFrame")));
    driver.findElement(By.linkText("com.thoughtworks.selenium")).click();
    System.out.println("The expected link is opened in the browser...");

However i get the error saying the 2nd frame that i am trying to switch to is not found.. While the frame name is present. Any pointers on what am i doing wrong here?

Thanks in advance

Upvotes: 2

Views: 689

Answers (1)

Prateek
Prateek

Reputation: 1145

So, now as you are already in the First frame and now your web driver would try to search the next frame 'within' this frame. You need switch to Default Content. Use `driver.switchTo().defaultContent();' :

    WebDriver driver= new FirefoxDriver();

    driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index");
    driver.switchTo().frame("classFrame");
    driver.findElement(By.linkText("com.thoughtworks.selenium")).click();
    System.out.println("The expected link is opened in the browser...");

    driver.switchTo().defaultContent();

    driver.switchTo().frame("packageListFrame");
    driver.findElement(By.linkText("com.thoughtworks.selenium")).click();
    System.out.println("The expected link is opened in the browser...");

Upvotes: 3

Related Questions