2

怎么可能

driver.findElement(By.cssSelector("input[id*='supplierOps_input'][class*='ui-autocomplete-input']")); 

抛出这个异常:org.openqa.selenium.NoSuchElementException : Returned node was not an HTML element.

driver.findElements(By.cssSelector("input[id*='supplierOps_input'][class*='ui-autocomplete-input']"));

效果很好,他的.size()回报 1(所以我只有 1 个元素),我可以使用 id 值.get(0).getAttribute("id");

我的大脑在挣扎。


更新 :

这是 POM.xml 中的 Selenium 部分

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-server</artifactId>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>servlet-api-2.5</artifactId>
    </exclusion>
  </exclusions>
</dependency>
4

1 回答 1

0

好的,我的大脑再次受伤,因为在这个问题之后的 2 天,我尝试做同样的事情,afindElement(By.cssSelector())和 afindElements(By.CssSelector())现在都很好用。

我也尝试过使用 xpath 并且效果很好,例如:

driver.findElement(By.xpath("//input[contains(@id,'supplierOps_input') and contains(@class,'ui-autocomplete-input')]"))

这可能不是一个真正的答案,因为我不知道为什么我第一次尝试使用 cssSelector 时给了我一个投掷:org.openqa.selenium.NoSuchElementException : Returned node was not an HTML element.

也许它不稳定,有时它会很酷,有时它会抛出..

于 2013-05-03T08:11:02.550 回答