【发布时间】:2021-08-21 07:37:40
【问题描述】:
我写了一个函数如下
public static WebElement waitForElementToBeClickable(WebDriver driver, WebElement webElement, int seconds) {
WebDriverWait wait = new WebDriverWait(driver, seconds);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(webElement));
element.click();
return element;
}
现在我正在导入这个函数并如下使用它
private String loginButton = "btnActive";
private String home = "//a[@id='pt1:_UIShome']";
WebElement login = driver.findElement(By.id(loginButton));
libraryUtils.waitForElements.waitForElementToBeClickable(driver, login, 20).click();
WebElement homeButton = driver.findElement(By.xpath(home));
libraryUtils.waitForElements.waitForElementToBeClickable(driver, homeButton, 20).click();
点击了登录按钮,但是在转到下一页后,我收到以下错误 -
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attach to the page document
Xpath 是正确的,我已经检查过了。当我使用element.click() 时,它也可以工作,但是这需要我手动输入睡眠时间,这就是我正在做的事情。我希望这是动态的。感谢任何帮助或建议。
【问题讨论】:
-
位于
//a[@id='pt1:_UIShome']XPath 的元素是否出现在第一页,loginButton 出现的位置? -
你能分享一个网站链接吗?
-
嘿抱歉,我不允许共享链接,但我登录后页面上没有带有 //a[@id='pt1:_UIShome'] 的元素
-
好的,这个元素是否在视图中,或者您必须滚动到它才能将它带到可见屏幕?最初上面是否有某种弹出窗口、微调器等?
-
它在视图中,不需要scrool或任何东西
标签: java selenium selenium-webdriver automation rpa