当我开始使用 Selenium 时,我发现很难对隐藏元素执行操作(悬停、单击等),这些元素只有在悬停在其他元素上时才可见。所以我希望这对其他人有帮助,您可以使用以下任何一种方法。
例如,要upvote
此页面中的评论,我需要将鼠标悬停在上下文(即评论)上以使向上箭头可见,然后我需要单击它。但使用javascriptExcecuter
您可以一步执行此操作。
//this can be used even if the element is not visible
//if you want to hover over the element, replace click() with hover()
((JavascriptExecutor)driver).executeScript("$('element_selector').click();");
OR
you can use Actions class rather than using the Keyboard or Mouse directly.
It implements the builder pattern: Builds a CompositeAction containing all actions specified by method calls
有关 Action 类的更多信息可以在这里找到。 http://code.google.com/p/selenium/wiki/AdvancedUserInteractions
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)