Reputation: 7601
Below is the html code:
<a href="javascript:void(0)">
STK10000251
VESUVIUS29
Vesuvius India Ltd
</a>
And I have written the following xpath:
driver.findElement(By.xpath("//a[contains(text(), 'STK10000251')]")).click();
After executing the above statement I'm getting below error:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
Where am I getting it wrong
Upvotes: 1
Views: 126
Reputation: 33384
Induce WebDriverWait
() and wait for elementToBeClickable
()
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(), 'STK10000251')]")));
element.click();
Upvotes: 1