簡體   English   中英

硒webdriver中的IE出現問題?

[英]Issue with IE in selenium webdriver?

我在使用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);
    }

我了解不建議您這樣做,但至少我不受阻礙,而且我的工作已經完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM