如何在HtmlUnitDriver中解决NoSuchElementException

时间:2013-10-07 11:34:33

标签: java selenium-webdriver htmlunit-driver

我正在尝试使用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();

} }

1 个答案:

答案 0 :(得分:0)

您是否尝试添加Thread.sleep以查看它是否是计时问题?