点击使用WebDriver的链接上的事件显示“;javascript:void(0)"状态栏上

Click event on link using WebDriver shows "javascript:void(0)" on status bar

本文关键字:void 状态栏 quot javascript WebDriver 链接 显示 事件      更新时间:2023-09-26

我正试图点击鼠标悬停事件生成的下拉列表中的第一个链接。

尝试了很多选项,但没有成功,只在状态栏上看到"javascript:void(0)"。到目前为止,设法在鼠标悬停时显示下拉列表。唯一的问题是点击第一个链接。

<a title="Insert" href="#">
    <span>Insert</span>
</a>
<ul>
     <li class="standardContent">
         <a id="id193" title="Modules & Topics from a Library" href="#"> Modules & Topics  from a Library </a>
     </li>
      <li class="customModule">

在这里我想点击元素"模块和主题从一个图书馆"。由于id是动态更改的。所以不能用来点击。

  Actions act = new Actions(driver);
        WebElement iconhover = driver.findElement(By.className("insertItems"));
        act.moveToElement(iconhover).click().build().perform();
        WebDriverWait wait = new WebDriverWait(driver,10);
        WebElement mod = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@class='standardContent']")));
        mod.click();

下一次尝试

  Actions act = new Actions(driver);
        WebElement iconhover = driver.findElement(By.className("insertItems"));
        act.moveToElement(iconhover).click().build().perform();
        WebDriverWait wait = new WebDriverWait(driver,10);
        WebElement mod = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@class='standardContent']")));
        WebElement a = driver.findElement(By.xpath("//*[@class='insertItems']/ul"));
        List <WebElement> ancartag= a.findElements(By.tagName("a"));
        for (int i=0; i<ancartag.size();i++){
            System.out.println(ancartag.get(0));
            ancartag.get(0).click();
        }

尝试下面的片段:

WebElement element = driver.findElement(By.tagName("Modules & Topics  from a Library"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);