0
我想在後臺使用HtmlUnitDriver運行我的腳本,但它每次都會拋出Nosuchelementexection,但它會獲取當前的URL。如何解決HtmlUnitDriver中的NoSuchElementException
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();
}}