我有工作代码:
options_elements = issn_dropdown.find_elements_by_xpath("//ul[contains(@id,'my_id')]//li")
options = [x.text for x in options_elements]
options_elemets
是5个selenium.webdriver.remote.webelement.WebElement
的数组,每个都包含text
。结果option
正是我所需要的。我为什么不能将其更改为:
options = issn_dropdown.find_elements_by_xpath("//ul[contains(@id,'my_id')]//li/text()")
?测试仅在此行失败,没有显示任何特定错误。
text()
中的[xpath
返回文本节点,Selenium不支持它。您的第一个代码块是正确的方法。