需要用于可见元素的xpath定位器 [英] Need xpath locators for visible elements
问题描述
我正在尝试对我的网站进行测试.在某些用户表单上遇到麻烦.诀窍在于,表单中文本字段的数量根据用户选项的不同而有所不同(代码中存在禁用的选项,但样式为<
I'm trying to make a test for my site. Having troubles on some user form. The trick is, that the number of text fields in the form varies depending in user options (disabled ones are present in the code, but have a style <displayed: none;
> tag), so I'm trying to find more flexible approach than locating every element one-by-one and filling the forms with try/except blocks.
我正在使用xpath定位器
I'm using an xpath locator
text_fields = driver.find_elements_by_xpath("//div[@class='form-line']/div[@class='form-inputs']/input[@type='text' and not(ancestor::div[@style='display: none;'])]")
麻烦的是,萤火虫只查找需要的元素,但是当我使用它的硒脚本时,即使没有< text_fields
的列表也可以得到所有元素
The trouble is that firebug locates only needed elements, but when I use it my selenium script, printing the list of text_fields
gives me all the elements, even without a <displayed: none;
> tag
我如何只获得可见元素?
How can I get only visible elements?
PS对不起,我的英语不好^ _ ^
PS Sorry for my bad English ^_^
推荐答案
您可以按通常方式获取所有表单元素,然后在列表上进行迭代并删除在
You can get all the form elements the usual way, then iterate on the list and remove those elements that do not return true on is_displayed()
.
这篇关于需要用于可见元素的xpath定位器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!