我正在尝试使用HtmlUnitDriver在后台运行我的脚本,但每次都会抛出Nosuchelementexection,但它会获得当前的url。
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Example{
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver(true);
driver.get("http://www.google.com");
String url=driver.getCurrentUrl();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
System.out.println(url);
String Text=driver.findElement(By.id("gbqfba")).getText();
System.out.println(Text);
driver.findElement(By.xpath("//*[@id='gbqfba']")).getSize().getHeight();
driver.findElement(By.xpath("//*[@id='gbqfba']")).getSize().getWidth();
driver.findElement(By.xpath("//*[@id='gbqfba']")).click();
driver.quit();
} }
答案 0 :(得分:0)
您是否尝试添加Thread.sleep以查看它是否是计时问题?