2014-01-24 30 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")); 
相關問題