有没有办法通过 xpath insted 获得标题driver.getTitle()
我尝试了以下方法:
By.xpath("//title")
但它没有用。例如堆栈溢出
public class TestStack {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://stackoverflow.com/");
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//title")));
System.out.println(driver.findElement(By.xpath("//title")).getText());
}
}
未找到 xpath 的元素