[英]Cannot find element using href or text()
元件:
<a href="https://rads.stackoverflow.com/amzn/click/com/B071NZZHF9" rel="nofollow noreferrer"> == $0
"
B071NZZHF9
"
嘗試過:
WebElement element = dr.findElement(By.xpath("//a[text()='B071NZZHF9']"));
並嘗試:
WebElement element = dr.findElement(By.xpath("//a[@href='http://www.amazon.com/gp/product/B071NZZHF9']"));
但是出現錯誤:無法找到元素並且無法單擊元素
按照您共享的HTML
來單擊WebElement
您可以使用:
dr.findElement(By.xpath("//a[@href='https://rads.stackoverflow.com/amzn/click/B071NZZHF9']")).click();
您可以使用此xpath並等待並嘗試
//a[contains(text(), 'B071NZZHF9')]
使用Explicit wait嘗試以下代碼:
WebDriverWait waitForElement= new WebDriverWait (20,dr);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(), 'B071NZZHF9')]")));
dr.findElement(By.xpath("//a[contains(text(), 'B071NZZHF9')]")).click();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.