我无法在我使用的硒中找到一个元素htmlUnitDriver
。很好的驱动程序工作正常,但我无法找到谷歌搜索文本框元素。
这是代码:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class SampleUnitDriver
{
public static void main(String[] args) throws Exception
{
HtmlUnitDriver unitDriver = new HtmlUnitDriver();
unitDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
unitDriver.get("http://google.com");
System.out.println("Title of the page is -> " + unitDriver.getTitle());
WebElement searchBox = unitDriver.findElement(By.xpath(".//*[@id='gs_htif0']"));
searchBox.sendKeys("Selenium");
WebElement button = unitDriver.findElement(By.name("gbqfba"));
button.click();
System.out.println("Title of the page is -> " + unitDriver.getTitle());
}
}
这是一个错误:
线程“主”org.openqa.selenium.NoSuchElementException 中的异常:无法使用 .//*[@id='gs_htif0'] 定位节点有关此错误的文档,请访问:http ://seleniumhq.org/exceptions /no_such_element.html 构建信息:版本:'2.53.0',修订:'35ae25b1534ae328c771e0856c93e187490ca824',时间:'2016-03-15 10:43:46' 系统信息:主机:'user-PC',ip:'192.168.1.52', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51' 驱动程序信息: driver.version: SampleUnitDriver at org.openqa.selenium.htmlunit .HtmlUnitDriver.findElementByXPath(HtmlUnitDriver.java:1165) 在 org.openqa.selenium.By$ByXPath.findElement(By.java:361) 在 org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1725)在 org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1367) 在 org.openqa 的 org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1721)。selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1721) at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:606) at com.digitalmqc.automation.action.SampleUnitDriver.main(SampleUnitDriver.java: 19)
任何帮助都将不胜感激。