2015-10-07 78 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); 
    } 

我明白,这不是建议,但至少我得到了畅通,我的工作完成。