Selenium webdriver中的鼠标悬停事件 [英] Mouse Over Event In Selenium webdriver

查看:171
本文介绍了Selenium webdriver中的鼠标悬停事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从菜单中显示子菜单

I am unable to reveal the sub menu from the menu

我尝试了以下方法1)我试过鼠标悬停(很明显)2)我试过javascript执行器

I tried Following methods 1) I tried Mouse over action (obvious one) 2)I tried javascript executor

问题是 HTML 组件仅在鼠标悬停时加载,因此无法设置 html 中不存在的元素的属性我正在使用 javahttps://www.milonic.com/index.php

problem is that the HTML component is loaded only on mouse over so unable to set attribute of the element which is not present in html I am using java https://www.milonic.com/index.php

推荐答案

悬停动作很好用,我写了一些测试代码,你可以根据自己的需要进行修改,点击这里的关于我们"链接标签关于米洛尼克"

The hover action works great, I've written a little testing code you can modify to your needs, here it clicks on the link "About us" in the tab "About Milonic"

您需要的是带有 ExpectedConditionswait 对象.在这里等待菜单中的元素可点击.

What you needed was the wait object with the ExpectedConditions. It is here to wait for the element in the menu to be clickable.

        driver.get("https://www.milonic.com/index.php");


        Actions action = new Actions(driver);

        WebElement hover = driver.findElement(By.id("el136"));      
        action.moveToElement(hover).build().perform();      

        WebDriverWait wait = new WebDriverWait(driver, 5);
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#tbl0 #pTR0 a")));
        element.click();

这篇关于Selenium webdriver中的鼠标悬停事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆