testing
testing

Reputation: 1796

How to mouse hover then need to click on the tab- Selenium WebDriver

enter image description here 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.

Upvotes: 0

Views: 2057

Answers (2)

Major
Major

Reputation: 455

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

Upvotes: 1

A Paul
A Paul

Reputation: 8251

This error comes if the element is not visible or enabled.

Here is two points from me 1. If you are hovering then properly using selenium just check if the element is visible or enabled. 2. Or use JavascriptExecutor. It can click on hidden elements with out opening them.

(JavascriptExecutor(webdriver)).executeScript("document.getElementsById('ext-pr-backlog-evolution').click();");

Upvotes: 1

Related Questions