2014-01-22 40 views
0

enter image description here 工作在硒webdriver首先我想鼠標需要懸停在圖像中顯示的選項卡。從年齡解決時間。使用Java如何鼠標懸停,然後需要點擊選項卡上 - Selenium WebDriver

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

儘量避免使用硬編碼睡眠,因爲它會減慢您的測試。

如何使用隱式等待?

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

1

如果元素不可見或未啓用,則會出現此錯誤。

這裏有兩點來自我 1.如果你正在盤旋然後正確使用硒只是檢查元素是否可見或啓用。 2.或使用JavascriptExecutor。它可以在不打開它們的情況下點擊隱藏的元素。

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

好友。您必須根據您的使用更改代碼。這是一個例子。像「webdriver」就會成爲你的「驅動程序」。使用javascriptexecutor導入「org.openqa.selenium.JavascriptExecutor」 –

+0

請向我建議任何解決方案或示例示例 – Amirdha

相關問題