本文介绍了如何鼠标悬停然后需要点击选项卡 - Selenium WebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!


在selenium webdriver上工作首先,我想要鼠标悬停到选项卡,如图所示。从年龄解析时间。使用 Java

  if(existsElement(ext-pr-backlog-evolution)== true){
WebElement menuHoverLink = driver.findElement(By.id(ext-pr-backlog-evolution)); //此行中的问题
actions.moveToElement(menuHoverLink).perform() ; //
JavascriptExecutor executor =(JavascriptExecutor)driver; //这是正确打开页面
executor.executeScript(arguments [0] .click();,driver.findElement(By.id (ext-pr-backlog-evolution))); //这是正确打开页面
Thread.sleep(6000);
}
else {
System.out.println(element not present - so it entered the else loop);
}

这是HTML标签

 < a id =ext-pr-backlog-evolutionclass =ext-pr-backlog-evolutionname =ext-pr-backlog-evolutionhref =https://10.4.16.159/extranet_prbacklogevolutiontendency/reports/type/default/>概述&进化< / A> 

在Image upto 问题报告(PR)中,鼠标悬停在尝试点击概述和评估标签,它正在移动到票单选项卡,但概述和Evloution 页面正在打开。确切的是打开选项卡,但不能悬停并点击。

解决方案

尽量避免使用硬编码的睡眠,因为它会减慢测试速度。 / p>

如何使用隐式等待?

  WebDriverWait wait = new WebDriverWait (司机,10); 
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id(someid)));

它的作用如下:


  1. 当元素存在时,继续测试

  2. 当元素不存在(当站点很慢时),它将抛出超时。

这是更好的测试,所以你知道为什么你的测试失败



更多信息:


Working on selenium webdriver First i want the mouse need to hover to tab which is shown in image. from Age to Time to Resolve. Using 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");
}

Here is the HTML tag

<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>

In the Image upto Problem Reports(PR) the mouse is hovering when trying to click on Overview and Evloution tab it is moving to Ticket tab but the Overview and Evloution page is opening. Exactly it is opening the tab but not hovering and clicking.

解决方案

Try to avoid using hardcoded sleep because it slows your test.

How about using the implicit wait?

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

What it does:

  1. When the element is present, continue on your test
  2. When the element is not present (when the site is slow), it will throw a timeout.

That is much better test so you know why your test fails

More info here: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

这篇关于如何鼠标悬停然后需要点击选项卡 - Selenium WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:17