簡體   English   中英

如何在Selenium 2中使用JavaScript執行器將鼠標懸停?

[英]How to mouse hover using javascript executor in selenium 2?

目前在Selenium WebDriver中使用Java 我想在鼠標懸停到選項卡上時執行操作,它需要單擊選項卡。 在此代碼中,我可以識別該元素,並且它正在打開選項卡。 但是問題在於它不是鼠標懸停和沒有點擊,而是直接打開頁面。

 JavascriptExecutor executor = (JavascriptExecutor)driver;
         executor.executeScript("arguments[0].click();",                                                     
driver.findElement(By.id("ext-pr-backlog-evolution") ));

如果我使用

WebElement menuHoverLink = driver.findElement(By.id("ext-pr-backlog-evolution"));
actions.moveToElement(menuHoverLink).click().perform();

它不能完全找到元素,而是單擊其他標簽。 所以我想將鼠標懸停在javascript執行器中。

您可以創建一個鼠標事件

document.createEvent('MouseEvents');

然后將鼠標懸停給它

mouseEventObj.initEvent( 'mouseover', true, true );

然后分派

element.dispatchEvent(mouseEventObj);

暫無
暫無

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

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