No such element exception | Internet explorer

2019-08-29 10:51发布

问题:

*** Updated the question with relevant html code.

I'm facing error while trying to select any value from dropdown.

The error is

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #oHeight

I have already set all the IE settings as mentioned in Selenium Docs

The code i have tried is mentioned below:

System.setProperty("webdriver.ie.driver", "D:\\Workspace\\Selenium\\Model\\servers\\IEDriverServer_32bit.exe");
    WebDriver driver = new InternetExplorerDriver();
    driver.manage().timeouts().implicitlyWait(15000, TimeUnit.MILLISECONDS);
    driver.get("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog2.htm");

    WebElement ddlHeight = driver.findElement(By.id("oHeight"));
    Select select = new Select(ddlHeight);
    select.selectByVisibleText("150");

    driver.findElement(By.xpath("//input[@value='Push To Create']")).click();

    driver.quit();

The system config is Windows 7 + IE 11

回答1:

You can try this code , It's working on my System : I'm using IE 11 + Win7 Professional:

Code

public class Sandeep {

    static WebDriver driver;
    static WebDriverWait wait;

    public static void main(String[] args) throws InterruptedException {
         System.setProperty("webdriver.ie.driver", "D:\\Automation\\IEDriverServer.exe");
            InternetExplorerOptions options =  new InternetExplorerOptions();
            options.ignoreZoomSettings();
            driver = new InternetExplorerDriver(options);
            driver.manage().window().maximize();
            wait = new WebDriverWait(driver, 40);
            driver.get("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog2.htm");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("oHeight")));
            wait.until(ExpectedConditions.elementToBeClickable(By.id("oHeight")));
            Select select = new Select(driver.findElement(By.id("oHeight")));
            select.selectByVisibleText("150");
//          wait.until(ExpectedConditions.elementToBeClickable(By.name("Push To Create")));
//          driver.findElement(By.name("Push To Create")).click();
            driver.close();

        }

    }

Please let me know if you have any concerns related to this.