如何在 Selenium 2 API 中处理鼠标悬停
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();
}
我正在尝试使用 selenium 2 编写下面的代码,但是,第三级弹出窗口不会停留很长时间来单击它,因此在第三级单击时会出现 ElementNotVisible 异常。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您至少可以在发送点击之前检查该元素是否可见:
这可以避免出现异常。我不确定是否有办法让弹出窗口停留的时间比应有的时间长。
You can at least check that the element is visible before you send your click:
This avoids the exception. I'm not sure there is a way to make the popup stay any longer than it should.