我无法获得以下html代码的xpath

时间:2019-07-02 10:29:40

标签: java selenium-webdriver xpath

我正在尝试获取以下HTML代码的XPath,但

Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException 

发生错误

我尝试过-

 driver.findElement(By.xpath("//li/a[@href='#home']")).click();

HTML

<a class="nav-link active show" data-toggle="tab" href="#home" role="tab" aria-selected="true">
  <svg class="olymp-register-icon">
    <use xlink:href="top10allthings.com/theme/app/svg-icons/sprites/…">
      <svg id="olymp-register-icon" viewBox="0 0 37 32">
        <title> register-icon </title>
      </svg>
    </use>
  </svg>
  <div class="ripple-container"> </div>
</a>

1 个答案:

答案 0 :(得分:1)

您似乎需要:

  1. 等到<div id="hellopreloader"消失
  2. 等待直到您的链接变为可点击

两者的答案是Explicit Wait通过Selenium Java client类在WebDriverWait中实现。

参考代码示例:

WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("hellopreloader"))); 
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#home']"))).click();

更多信息:How to use Selenium to test web applications using AJAX technology