没有这样的元素例外| Internet Explorer

时间:2018-04-14 13:07:08

标签: selenium internet-explorer selenium-webdriver nosuchelementexception

***使用相关的html代码更新了问题。

我在尝试从下拉列表中选择任何值时遇到错误。 enter image description here

错误是

  

线程“main”中的异常org.openqa.selenium.NoSuchElementException:无法找到带有css选择器的元素== #oHeight

我已经设置了Selenium Docs

中提到的所有IE设置

我试过的代码如下所述:

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();

系统配置是Windows 7 + IE 11

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此代码,它正在我的系统上运行: 我正在使用IE 11 + Win7 Professional:

代码

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();

        }

    }

如果您对此有任何疑虑,请与我们联系。