Jrawr Jrawr - 3 months ago 13
Java Question

Selenium not click proper target in IE via moveToElement, works in Chrome

I'm using the following to navigate a menu in Selenium. It works perfectly in Chrome, however in IE, it ends up clicking the menu below my target and the submenu item becomes completely inaccessible.

// Actions not supported by FireFox's Marionette Driver, use chrome or ie.
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.id("m7f8f3e49_ns_menu_INVENTOR_MODULE_a_tnode"));
System.out.println("Found the inventory text");
actions.moveToElement(menuHoverLink);

WebElement subLink = driver.findElement(By.id("m7f8f3e49_ns_menu_INVENTOR_MODULE_sub_changeapp_INVENTOR_a"));
actions.moveToElement(subLink);
actions.click();
actions.perform();


And here is where the drive is initialized

System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer64.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


I would like to be able to click on the proper menu item to continue with my testing.

Answer

I managed to get a working solution by moving the cursor over from the offset. Not sure how well this will work across screens.

Actions actions = new Actions(driver);
    WebElement menuHoverLink = driver.findElement(By.linkText(arg1));

    //<span id="m7f8f3e49_ns_menu_INVENTOR_MODULE_a_tnode">Inventory</span>
    System.out.println("Found the inventory text");
    actions.moveToElement(menuHoverLink);
    actions.moveByOffset(100, 10);

    Thread.sleep(1000);
    //actions.moveByOffset(45, 0);
    WebElement subLink = driver.findElement(By.
            id("m7f8f3e49_ns_menu_INVENTOR_MODULE_sub_changeapp_SRVITEM_a_tnode"));
    actions.moveToElement(subLink, 100, 12)
    .click().perform();