gpt4 book ai didi

java - Webdriverwait 未按预期工作

转载 作者:行者123 更新时间:2023-12-01 09:06:39 25 4
gpt4 key购买 nike

看来我的代码是正确的,但没有按预期工作,Webdriver 并没有真正在我的代码中工作。我希望在返回上一页之前先加载该页面。下面是我的代码。

Browser.clickElement(MenuButton, "XPath", _driver);

Browser.clickElement(Menus[i], "XPath", _driver);

for(int j=0; j<1; j++) //StrategySubLinks.length;
{
Browser.clickElement(StrategySubLinks[j], "XPath", _driver);
//wait for a certain element to be visible before going back to the previous page
//wait for the footer link
WebDriverWait wait = new WebDriverWait(_driver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"asdfdasf-asdfasdfcookie\"]/p/a[2]")));



//go back to previous page
//_driver.navigate().back();
_driver.navigate().refresh();
JavascriptExecutor js = (JavascriptExecutor) _driver;
js.executeScript("window.history.back();");

最佳答案

尝试以下:

WebDriverWait wait = new WebDriverWait(dr, 30);
wait.until(ExpectedConditions.jsReturnsValue("return document.readyState==\"complete\";"));

void waitForLoad(WebDriver driver) {
ExpectedCondition<Boolean> pageLoadCondition = new
ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}

关于java - Webdriverwait 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41217494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com