Selenium Java -HtmlUnitDriver-找不到页面上的任何元素?

时间:2019-04-08 05:57:48

标签: java selenium-webdriver

   WebDriver driver = new HtmlUnitDriver(true);
    driver.get("MYURL");
WebElement name = driver.findElement(By.id("your_name"));

错误如下

Exception in thread "main" org.openqa.selenium.NoSuchElementException: 
Unable to locate element with ID: 'your_name'
For documentation on this error, please visit: 
https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
 System info: host: 'DESKTOP-0DI3NHE', ip: '192.168.0.45', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
  Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementById(HtmlUnitDriver.java:1251)
at org.openqa.selenium.By$ById.findElement(By.java:188)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2020)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2016)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1642)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:2016)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:794)

这是通过chrome开发人员工具查看时页面的html

<input id="your_name" class="hinted hintshown" name="name" type="text" placeholder="Your name (required)" value="" tabindex="1" style="background: rgb(247, 247, 247);">

0 个答案:

没有答案