How to perform mouseover function in Selenium WebDriver using Java? Ask Question

How to perform mouseover function in Selenium WebDriver using Java? Ask Question

I want to do mouseover function over a drop down menu. When we hover over the menu, it will show the new options. I tried to click the new options using the xpath. But cannot click the menus directly. So, as the manual way I am trying to hover over the drop down menu and then will click the new options.

Actions action = new Actions(webdriver);
WebElement we = webdriver.findElement(By.xpath("//html/body/div[13]/ul/li[4]/a"));
action.moveToElement(we).build().perform();

ベストアンサー1

実際には、「マウスホバー」アクションを実行することはできません。代わりに、実行したいすべてのアクションを 1 回で連鎖させる必要があります。したがって、他のアクションを表示する要素に移動し、同じ連鎖中に、現在表示されている要素に移動してクリックします。

アクション チェーンを使用するときは、「ユーザーと同じように実行する」ことを覚えておく必要があります。

Actions action = new Actions(webdriver);
WebElement we = webdriver.findElement(By.xpath("html/body/div[13]/ul/li[4]/a"));
action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath("/expression-here"))).click().build().perform();

おすすめ記事