使用 selenium webdriver 首先,我希望鼠标需要悬停在图像中显示的选项卡上。从年龄到解决问题的时间。使用Java。
if(existsElement("ext-pr-backlog-evolution")==true){
WebElement menuHoverLink = driver.findElement(By.id("ext-pr-backlog-evolution"));// Problem in this line
actions.moveToElement(menuHoverLink).perform();//
JavascriptExecutor executor = (JavascriptExecutor)driver;// This is exactly opening the page
executor.executeScript("arguments[0].click();", driver.findElement(By.id("ext-pr-backlog-evolution") ));// This is exactly opening the page
Thread.sleep(6000);
}
else{
System.out.println("element not present -- so it entered the else loop");
}
这是 HTML 标签
<a id="ext-pr-backlog-evolution" class=" ext-pr-backlog-evolution" name="ext-pr-backlog-evolution" href="https://10.4.16.159/extranet_prbacklogevolutiontendency/reports/type/default/">Overview & Evolution</a>
在问题报告(PR)之前的图像中,当尝试单击概览和演进选项卡时,鼠标悬停在鼠标上,该选项卡正在移动到票证> 选项卡,但概述和 Evloution 页面正在打开。确切地说,它是打开选项卡,但不是悬停和单击。
最佳答案
尽量避免使用硬编码 sleep ,因为它会减慢测试速度。
使用隐式等待怎么样?
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
它的作用:
- 当该元素存在时,继续测试
- 当元素不存在时(当站点速度很慢时),它将抛出超时。
这是更好的测试,因此您知道测试失败的原因
更多信息请点击:http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp
关于java - 如何鼠标悬停然后需要单击选项卡-Selenium WebDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21276350/