0

I have a hidden svg tag which shows an image only after mouse hover to it:

[![<div id="available_roles" bp-org-diagram="" data-options="myOptions" data-on-highlight-changed="onMyHighlightChanged()" data-on-cursor-changed="onMyCursorChanged()" style="height: 95%; width: 100%; overflow: hidden;" class="ng-isolate-scope ui-widget"><div tabindex="0" class="famdiagram" style="position: relative; overflow: auto; top: 0px; left: 0px; width: 732px; height: 760px; padding: 0px; margin: 0px; display: block;"><div class="placeholder famdiagram" style="position: absolute; overflow: hidden; top: 0px; left: 0px; width: 707px; height: 735px; transform-origin: 0px 0px 0px; transform: scale(1, 1);">
<div class="Layer9" style="position: absolute; width: 0px; height: 0px;">
<svg version="1.1" viewbox="0 0 260 237.5" style="width: 260px; height: 237.5px; position: absolute;">
<path fill="#000000" fill-opacity="0.2" stroke="transparent" stroke-width="0" stroke-dasharray="" d="M50.5 74.5L122.5 74.5L130.5 50.5L138.5 74.5L210.5 74.5Q214.5 74.5 214.5 78.5L214.5 188.5Q214.5 192.5 210.5 192.5L50.5 192.5Q46.5 192.5 46.5 188.5L46.5 78.5Q46.5 74.5 50.5 74.5" style="visibility: hidden;"></path>
</svg>
<div class="bp-item bp-corner-all bt-item-frame" style="width: 160px; height: 110px; top: 77.5px; left: 50px; position: absolute; padding: 0px; margin: 0px; visibility: hidden;">][1]][1]

I have tried following and not successful so far:

WebElement we = driver.findElement(By.cssSelector("#available_roles>div>div>div.calloutplaceholder.famdiagram>div>svg"));
            Actions action = new Actions(driver);
            action.moveToElement(we).moveToElement(driver.findElement(By.cssSelector("#available_roles>div>div>div.calloutplaceholder.famdiagram>div>svg>path"))).click().build().perform();
4

1 Answer 1

0

Hi please try following function its JAVA SCRIPT mouse hover that will solve your problem as it did for me

public void mouseHoverJScript(WebElement HoverElement) {
        try {
            if (isElementPresent(HoverElement)) {

                String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', 

true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
                ((JavascriptExecutor) driver).executeScript(mouseOverScript,
                        HoverElement);

            } else {
                System.out.println("Element was not visible to hover " + "\n");

            }
        } catch (StaleElementReferenceException e) {
            System.out.println("Element with " + HoverElement
                    + "is not attached to the page document"
                    + e.getStackTrace());
        } catch (NoSuchElementException e) {
            System.out.println("Element " + HoverElement + " was not found in DOM"
                    + e.getStackTrace());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error occurred while hovering"
                    + e.getStackTrace());
        }
    }

    public static boolean isElementPresent(WebElement element) {
        boolean flag = false;
        try {
            if (element.isDisplayed()
                    || element.isEnabled())
                flag = true;
        } catch (NoSuchElementException e) {
            flag = false;
        } catch (StaleElementReferenceException e) {
            flag = false;
        }
        return flag;
    }`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.