gpt4 book ai didi

python - 如何使用 Selenium 和 Python 从通过 xpath 找到的 webdriver 元素中提取文本

转载 作者:行者123 更新时间:2023-12-04 15:35:09 32 4
gpt4 key购买 nike

我有工作代码:

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

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

最佳答案

xpath 中的

text() 返回文本节点,Selenium 不支持。你的第一个代码块是要走的路。

关于python - 如何使用 Selenium 和 Python 从通过 xpath 找到的 webdriver 元素中提取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60038708/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com