0
votes

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();

1

1 Answers

0
votes

I'm using to following code to hover over an element:

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

Try if it works.

I'm not sure you can click on that li element, since it is invisible. Shouldn't you hover your link (a tag)?