如何单击链接WebDriver的“单击”方法,Actions类和JavascriptExecutor不起作用?

时间:2019-07-05 14:32:54

标签: selenium webdriver

enter image description here

HTML:

<div id="NarrowResultsSection">
   <div id="b_narrowClearAll"><span>Your Filter Selections</span> <a href="/search/everything?searchField=*&amp;category=everything&amp;searchFilter=" class="narrow-clear-all">Clear All</a></div>
   <div id="b_narrowClear">Books, Movies &amp; More<a href="/search/everything?searchField=*&amp;category=everything&amp;searchFilter=">Remove</a></div>
   <div id="b_narrowMedium">Medium: Books <a href="https://qa.qbpl.org/search/book?searchField=*&amp;category=book&amp;searchFilter=%20%20sm_format:book.audiobook">Remove</a></div>
   <div id="b_narrowMedium">Medium: Audiobooks <a href="https://qa.qbpl.org/search/book?searchField=*&amp;category=book&amp;searchFilter=%20sm_format:book%20">Remove</a></div>
</div>

错误消息:

org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element

1 个答案:

答案 0 :(得分:0)

要单击Medium: Audiobooks,请使用WebdriverWaitelementToBeClickable,然后单击元素。您可以使用以下xpath。

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='b_narrowMedium'][contains(.,'Medium: Audiobooks')]/a[contains(.,'Remove')]"))).click();