你如何利用点击硒的webdriver是隐藏的元素? [英] How do you click on an element which is hidden using Selenium WebDriver?

查看:171
本文介绍了你如何利用点击硒的webdriver是隐藏的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用webdriver的自动化Web应用程序和的Python

I have a web application which I am automating using WebDriver and Python.

问题是,有一个菜单是这样的
如果我手动点击箭头按钮,它扩展到另一个子菜单从那里我需要选择一个特定的领域。

The issue is that there is a menu something like this if I click manually on the arrow button it expands to another submenu from where I need to select a particular field.

我觉得这第三个菜单,但它当我点击使用的 element.click(),而不是扩展菜单,显示我的子菜单项,它显示合并所有的子菜单的内容。

I can find this third menu but when I click on it using element.click() instead of expanding the menu and showing me its sub menu items it is showing consolidated contents of all the sub menu.

(手动扩大到子菜单是由组名之前实际点击小箭头图标来实现)
那么,如何实际点击这个箭头图标展开组菜单的一成子菜单。

(Manually the expansion to sub menu is achieved by actually clicking on the small arrow icons before the group names) So how do I actually click on this arrow icons to expand one of the group menu into sub menus.

这是 HTML 对应的第三组菜单是否有帮助。

This is the HTML corresponding to third group menu if it helps.

<div id="node_3_item" class="treeLabelSelected" style="padding-left: 0px; background-position: 0px -24px;">
<span style="background-position: 0px -24px;">XXX Groups</span>
</div>
<div style="display: none;"></div>
</div>

显示:无行实际上是隐藏子菜单(据我可以做出来)

The display: none line is actually hiding the sub menu (as far as I can make out)

如何处理将是AP preciated任何建议。
谢谢

Any suggestion on how to handle will be appreciated. Thanks

请注意:我已经通过SO相关的几个问题去隐藏的网页元素进行交互,但他们跟我的情况有所不同。

Note: I have already gone through several questions on SO related to interacting with hidden web elements but they differ with my situation.

推荐答案

抢元素要点击:

# Or using xparth or something
element = driver.find_element_by_css_selector(css_selector)

点击它使用javascript:

Click it using javascript:

driver.execute_script("$(arguments[0]).click();", element)

注:我使用jQuery否则选择它原生的JavaScript

这篇关于你如何利用点击硒的webdriver是隐藏的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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