0

I am trying to click a hover over 'edit' button. However, I keep getting "Element is not currently visible and so may not be interacted with" Error when I use mouseOverElement.
Any idea on how to make it work? Thanks

< div class="editbox" >
 < h2>Title< /h2>
  < ul>
    < li >
       < small class="editlinks" >
            < a class="edit" href="#">Edit< / a >
       < /small>
     < strong> Content
    < /li>
  < /ul>
< /div>

Here is my code:

Approach 1:

WebElement textArea = driver.findElement(By.cssSelector("div.editbox ul li"));
WebElement button = driver.findElement(By.cssSelector("div.editbox ul li small.editlinks a.edit"));
Actions builder = new Actions(driver);
builder.moveToElement(textArea).build().perform();
timer.wait(5000);
driver.findElement(By.cssSelector("div.editbox ul li small.editlinks a.edit")).clik();

Approach 2:

Actions builder = new Actions(driver);
builder.moveToElement(textArea);
timer.wait(5000);
builder.click(button);
builder.build().perform();

4

1 回答 1

0

我正在使用以下代码将鼠标悬停在元素上:

if (element instanceof Locatable) {
    Locatable hoverItem = (Locatable) element;
    hoverItem.getLocationOnScreenOnceScrolledIntoView();
    Mouse mouse = ((HasInputDevices) webDriver).getMouse(); 
    mouse.mouseMove(hoverItem.getCoordinates());
}

试试看是否有效。

我不确定您是否可以单击该li元素,因为它是不可见的。你不应该悬停你的链接(a标签)吗?

于 2013-01-08T22:10:11.120 回答