【问题标题】:No such element exception | Internet explorer没有这样的元素异常 | IE浏览器
【发布时间】:2018-04-14 13:07:08
【问题描述】:

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

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

错误是

线程“主”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

【问题讨论】:

  • 用相关的HTML更新问题
  • @DebanjanB 已更新,请检查并让我知道以寻求帮助。
  • 为什么选择元素使用name 而不是id
  • @RatmirAsanov 我很糟糕,我已将其更改为 id 但仍然出现相同的错误。
  • @SandeepRaulo,你在哪一行代码之后出现了这个错误?

标签: selenium internet-explorer selenium-webdriver nosuchelementexception


【解决方案1】:

你可以试试这个代码,它在我的系统上运行: 我正在使用 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();

        }

    }

如果您对此有任何疑虑,请告诉我。

【讨论】:

  • 我也尝试了你的代码,但仍然出现以下错误:rg.openqa.selenium.support.ui.ExpectedConditions findElement WARNING: WebDriverException throw by findElement(By.id: oHeight) org.openqa。 selenium.JavascriptException:我认为 IE 设置存在一些问题。
  • IE 可能有问题。您可以在不同/虚拟机上尝试此代码,因为它在我的系统中运行得非常好。
  • 您是否对您的 IE 设置进行了任何更改?如果是,请与我分享。
  • 昨天我打开IE的时候,有一些设置IE默认浏览器的弹窗,我选择了“不要再问我”选项,就成功了。
  • 哦。那我真倒霉。我已按照 Selenium 文档中的说明进行了所有更改,但没有解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多