How to handle Mouseover in Selenium 2 API

半城伤御伤魂 提交于 2019-12-07 22:25:43

问题


String strPrimaryNav = "MEN";
String strSecondaryNav = "Shoes";
String strTertiaryNav = "Golf";

driver.findElement(By.linkText(strPrimaryNav)).click();

WebElement weSecNav = driver.findElement(By.className("secondaryButton").linkText(strSecondaryNav));

Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseDown(((Locatable)weSecNav).getCoordinates());
//just trying with for loop as the tertiary popup disappears quickly and hence getting ElementNotVisible Exception
for (int i = 0 ; i< 2; i++){
    mouse.mouseDown(((Locatable)weSecNav).getCoordinates());
    //mouse.mouseMove(((Locatable)weSecNav).getCoordinates(), 0, 0 );
    //WebElement weTerNav = driver.findElement(By.className("tertiaryButton").linkText(strTertiaryNav));
    WebElement weTerNav = driver.findElement(By.linkText(strTertiaryNav));
    boolean isSecDisplayed = ((RenderedWebElement)weTerNav).isDisplayed();
    System.out.println("isDisplayed: " + isSecDisplayed);
    System.out.println(" " + ((RenderedWebElement)weSecNav).getAttribute("href"));
    System.out.println(" " + ((RenderedWebElement)weSecNav).getValueOfCssProperty("action"));
    weTerNav.click();
}

I was trying the below code using selenium 2 but, the tertiary popup not stays long to click it and hence getting ElementNotVisible exception at Tertiary click.


回答1:


You can at least check that the element is visible before you send your click:

Selenium s = new WebDriverBackedSelenium( driver, URL );
s.waitForCondition( "!( document.getElementById('.....') === null )", "20000" );
s.click( .... );

This avoids the exception. I'm not sure there is a way to make the popup stay any longer than it should.



来源:https://stackoverflow.com/questions/5981656/how-to-handle-mouseover-in-selenium-2-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!