selenium webdriver中的IE问题

Issue with IE in selenium webdriver?

本文关键字:问题 IE 中的 webdriver selenium      更新时间:2023-09-26

我在使用webdriver代码的IE中面临鼠标悬停问题,它在Chrome和Firefox中工作正常,但鼠标悬停问题仅在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();  

我多次遇到过同样的问题,因为我必须主要在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);
    }

我知道这是不推荐的,但至少我得到了解决,我的工作完成了。