简体   繁体   English

无法在Selenium Webdriver Java中的元素上选择鼠标

[英]Unable to select mouse over elements in Selenium Webdriver Java

I am automating a web application using selenium webdriver and java. 我正在使用Selenium Webdriver和Java自动化Web应用程序。 It has few mouse over elements which I am not able to automate. 它几乎没有鼠标悬停的元素,我无法实现自动化。 Mouse over works well and newly visible elements locate properly when I record and play in Selenium IDE but same is not working when I run in eclipse. 当我在Selenium IDE中录制和播放时,鼠标悬停效果很好,新可见的元素可以正确定位,但是在Eclipse中运行时,它们却无法正常工作。 I have automated similar mouse over elements earlier but facing difficulty in automating this. 我早些时候已经将类似的鼠标悬停在元素上,但是在自动化方面面临困难。 I have attached screenshot of a web application and the code for mouse over elements and here I am not able to mouse over on "Configuration" menu and select "Configure Hierarchy Metadata". 我已经附上了一个Web应用程序的屏幕快照以及将鼠标悬停在元素上的代码,在这里,我无法将鼠标悬停在“配置”菜单上并选择“配置层次结构元数据”。 It would be really great if anybody could help me out in this!! 如果有人可以在这方面帮助我,那将真是太好了! Let me know if any more details needed. 让我知道是否需要更多详细信息。 Thanks in advance. 提前致谢。

鼠标悬停菜单和代码

This is a very common issue. 这是一个非常普遍的问题。 You need to make sure you are interacting with the element that has the hover listener.. 您需要确保正在与具有悬停侦听器的元素进行交互。

In this case, it looks like it is the <a> that is receiving the hover. 在这种情况下,看起来是<a>正在接收悬停。 Try moving to element (hovering over): 尝试移至元素(悬停):

By.cssSelector("ul.topmenu li:nth-child(2) > a[title='Configurations']");

In order to achieve this, you will first have to hover on element(say - element1) which makes element to be clicked(say - element2) on visible and then click on the option from list - 为了实现这一点,您首先必须将鼠标悬停在element(say-element1)上,这将使元素在可见状态下被单击(say-element2),然后单击列表中的选项-

Actions actions = new Actions(driver);
actions.moveToElement(element1).moveToElement(element2).click(element2).build().perform();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM