簡體   English   中英

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

執行上述語句后,我收到以下錯誤:

線程“主”org.openqa.selenium.StaleElementReferenceException 中的異常:過時元素引用:元素未附加到頁面文檔

我在哪里弄錯了

誘導WebDriverWait () 並等待elementToBeClickable ()

WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(), 'STK10000251')]")));
element.click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM