2015-10-07 72 views
2

我在使用webdriver代碼的IE中遇到了鼠標懸停的問題,它在Chrome和Firefox中工作正常,但鼠標懸停問題只發生在IE中。我該如何解決這個問題?首先焦點的元素上,並在旁邊,我會點擊鏈接,請參見下面的代碼,selenium webdriver中的IE問題?

WebElement newbutton = driver.findElement(By.xpath("//html/body/div/span/form[2]/div/div/div[3]/div[2]/ul/span/li"));  
Actions action = new Actions(driver);  
action.moveToElement(newbutton).build().perform();  
WebElement nextButton=driver.findElement(By.xpath(".//*[@id='menuFmId:headerForm:j_id130']/li/span")); 

Actions action1 = new Actions(driver); 
action1.moveToElement(nextButton).click(nextButton).build().perform(); 
+0

請發佈您的HTML代碼,以便人們能夠更好地理解問題出在哪裏,因爲您在第一個按鈕中使用絕對xpath可能在IE中沒有檢測到它,必須查看代碼。 –

回答

0

我所面對的同類問題很多很多時間,因爲我必須大多IE瀏覽器。這些頁面在IE上表現得相當出人意料。花了很多時間嘗試搜索傳統的方法來實現IE中的懸停之後,我最終使用了Javascript。

public void mouseHoverJScript(WebElement HoverElement) { 
     String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}"; 
     ((JavascriptExecutor) driver).executeScript(mouseOverScript, HoverElement); 
    } 

我明白,這不是建議,但至少我得到了暢通,我的工作完成。