无法使用 Selenium Java webdriver 单击锚点 href 元素
Could not click on anchor href element using Selenium Java webdriver
下面是html代码:
<a href="javascript:void(0)">
STK10000251
VESUVIUS29
Vesuvius India Ltd
</a>
我写了下面的 xpath:
driver.findElement(By.xpath("//a[contains(text(), 'STK10000251')]")).click();
执行上述语句后出现以下错误:
Exception in thread "main"
org.openqa.selenium.StaleElementReferenceException: stale element
reference: element is not attached to the page document
我哪里弄错了
诱导WebDriverWait
()并等待elementToBeClickable
()
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(), 'STK10000251')]")));
element.click();
下面是html代码:
<a href="javascript:void(0)">
STK10000251
VESUVIUS29
Vesuvius India Ltd
</a>
我写了下面的 xpath:
driver.findElement(By.xpath("//a[contains(text(), 'STK10000251')]")).click();
执行上述语句后出现以下错误:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
我哪里弄错了
诱导WebDriverWait
()并等待elementToBeClickable
()
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(), 'STK10000251')]")));
element.click();