简体   繁体   中英

Could not click on anchor href element using Selenium Java webdriver

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM