从xpath找到的webdriver元素中提取文本

问题描述 投票:0回答:1

我有工作代码:

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()")

?测试仅在此行失败,没有显示任何特定错误。

python selenium xpath ui-testing
1个回答
1
投票

text()中的[xpath返回文本节点,Selenium不支持它。您的第一个代码块是正确的方法。

© www.soinside.com 2019 - 2024. All rights reserved.