Hover over an SVG contained in img tag using Selenium Java

Viewed 181

The element I'm trying to hover is an SVG(Vertical Ellipsis icon) which is contained in a img tag.

I've tried using

  1. Actions class moveToElement method
    WebElement element = driver.findElement(By.xpath(""));
    actions.moveToElement(element);
    actions.click().build().perform();
  1. Javascript Executor method as described in
    How to do Mouse hover on Image in selenium web driver to get menu list

Both of them doesn't work.

The structure of the element is like..

<div>
    <div>
        <img src="ellipsis.svg">
    </div>
</div>

Similar svg can be found at https://icons.getbootstrap.com/icons/three-dots-vertical/

1 Answers

there's a special way to locate svg tag :

Let's say you have a svg tag like below :

<svg id="some id" class = "someclass" and other attributes>
    <div>
    <div>
        <img src="ellipsis.svg">
    </div>
</div>
</svg>

Then you can try this :

//*[name()='svg' and contains(@class, 'someclass')]//descendant::img[contains(@src, 'ellipsis.svg')]
Related