我正在使用 Selenium WebDriver 使用 Python 进行 UI 测试,我想检查以下 HTML:
<ul id="myId">
<li>Something here</li>
<li>And here</li>
<li>Even more here</li>
</ul>
我想从这个无序列表中循环遍历元素并检查其中的文本。我通过其选择了 ul 元素id
,但我找不到任何方法来循环<li>
-硒中的孩子们。
有谁知道如何循环<li>
-Selenium 的无序列表的子代(在 Python 中)?
您需要使用.find_elements_by_
method.
例如,
html_list = self.driver.find_element_by_id("myId")
items = html_list.find_elements_by_tag_name("li")
for item in items:
text = item.text
print text
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)