1

using the below code, i am not able to find the element. i am getting error element not found

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class CreateMars {

    public static void main(String[] args) {
        WebDriver driver=new FirefoxDriver();

        driver.get("http://gimmewings.com");
        driver.manage().window().maximize();
        WebElement web=driver.findElement(By.id("drop3"));
        driver.close();
    } 

1 Answer 1

3

The problem is the element you are trying to find is inside of a <frame>. Selenium requires that you use switchTo().frame() to access that frame prior to locating elements inside of it.

public static void main(String[] args) {
    WebDriver driver=new FirefoxDriver();

    driver.get("http://gimmewings.com");
    driver.manage().window().maximize();
    driver.switchTo().frame("TopFrame");
    WebElement web=driver.findElement(By.id("drop3"));
    driver.switchTo().defaultContent();
    driver.close();
}

When finished in the frame, you need to switch back to the top, using switchTo().defaultContent().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.