2014-01-24 31 views
0

enter image description here 工作在硒webdriver首先,我想鼠标需要悬停在图像中显示的选项卡。从年龄解决时间。使用Java如何鼠标悬停,然后需要点击选项卡 - Selenium2

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页面正在打开。确切地说,它是打开选项卡,但不是悬停和点击。

回答

1

正确的页面打开,因为,您正在使用javascript进行点击,即使对于未显示的元素,也可以执行点击。 尝试点击您的动作构建器。

WebElement menuHoverLink = driver.findElement(By.linkText("Overview & Evolution")); 
actions.moveToElement(menuHoverLink).click().perform(); 

不要忘记评论您的JavaScript点击。

+0

我试着用你的代码..问题在于它悬停**问题报告**上面出现**票证**选项卡,并打开**平均时间分配**选项卡。我不知道这是如何发生的。我在开始运行你的代码之前评论Javascript。 – Amirdha

+0

有没有其他方法可以解决这个问题。使用JavaScript执行器,我可以正确地找到元素。但同时它需要鼠标悬停,然后它需要点击选项卡。请任何人帮助我dix – Amirdha

+0

确切的鼠标悬停然后单击,您将不得不使用“actions.moveToElement(menuHoverLink).click()。perform();”。尝试** Amith **建议的。使用不同的定位器,如linktext。您还可以在点击功能中传递要点击的元素。 – Husam

0

您是否尝试过通过linkText寻找元素,我知道用id是找到的元素,但有不同的选择尝试可能会帮助你更接近问题的最好方式..

WebElement menuHoverLink = driver.findElement(By.linkText("Overview & Evolution")); 
相关问题