java - 如何鼠标悬停然后需要单击选项卡-Selenium WebDriver

标签 java extjs selenium selenium-webdriver

enter image description here 使用 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")));

它的作用:

  1. 当该元素存在时,继续测试
  2. 当元素不存在时(当站点速度很慢时),它将抛出超时。

这是更好的测试,因此您知道测试失败的原因

更多信息请点击:http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

关于java - 如何鼠标悬停然后需要单击选项卡-Selenium WebDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21276350/

相关文章:

javascript - 在 extjs 中添加 html 编辑器字段所需的验证器?

java - 如何使用 Java 通过 Selenium RC 和 TestNG 顺序运行/执行方法

java - ImageView 在其可绘制对象之间闪烁

java - 在 spring 4 中, Controller 生成纯文本而不是 html

javascript - 一键保存多个选项卡面板

python - Selenium click 可以与标签一起使用吗?

Java for 循环总是返回 true

java - Hazelcast 更新复制 map

java - 在Java中生成序列号

extjs - 如何在 Ext.formPanel 中隐藏标题