我正在尝试为我的网站进行测试。在某些用户表单上遇到麻烦。诀窍是,表单中文本字段的数量取决于用户选项(禁用的代码存在于代码中,但具有样式< displayed: none;
> tag),所以我试图找到比定位每个元素更灵活的方法元素一个接一个,用try/except块填充表单。需要可见元素的xpath定位器
我使用XPath定位
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
名单给我的所有元素,即使没有< displayed: none;
>标签
如何获取仅可见元素?
PS对不起,我的英文不好^ _^
def make_an_order(driver): text_fields = driver.find_elements_by_xpath(“// div [@ class ='form-line']/div [@ class ='form-inputs']/input [@ type ='text “) 用于text_fields字段: 尝试: field.clear() 除外: 通 实测值的溶液中。但问题仍然很有趣 – 2012-04-19 11:15:25
注入jQuery并使用[':visible'](http://api.jquery.com/visible-selector/)选择器替代? – Alp 2012-04-19 11:23:09