您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python Selenium:查找h1元素,但返回空文本字符串

Python Selenium:查找h1元素,但返回空文本字符串

问题在于,有两个h1外部元素完全相同的元素HTML:第一个元素是隐藏的,第二个元素不是。你可以用

print(len(driver.find_elements_by_xpath('//h1[@class="product-title "]')))

text属性允许您 *

尝试更换

new_name = driver.find_element_by_xpath(xp_name).text

new_name = driver.find_element_by_xpath(xp_name).get_attribute('textContent')

或简单地处理第二个(可见)标头:

driver.find_elements_by_xpath('//h1[@class="product-title "]')[1].text
python 2022/1/1 18:37:50 有232人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶