相关疑难解决方法(0)

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

我想在此页面的标题中获取文本:

在此输入图像描述

iShares FTSE MIB UCITS ETF EUR(Dist)

标签看起来像这样:

<h1 class="product-title" title="iShares FTSE MIB UCITS ETF EUR (Dist)"> iShares FTSE MIB UCITS ETF EUR (Dist) </h1>
Run Code Online (Sandbox Code Playgroud)

我正在使用这个xPath:

xp_name = ".//*[@class[contains(normalize-space(.), 'product-title')]]"
Run Code Online (Sandbox Code Playgroud)

.text在Selenium WebDriver for Python中检索:

new_name = driver.find_element_by_xpath(xp_name).text
Run Code Online (Sandbox Code Playgroud)

驱动程序找到xpath,但是当我打印时new_name,macOS Terminal只打印一个空字符串:""

这可能是什么原因?

在此输入图像描述


注意:我还尝试了一些其他的xpath替代方案,获得相同的结果,例如:

xp_name = ".//*[@id='fundHeader']//h1"
Run Code Online (Sandbox Code Playgroud)

python selenium xpath hidden

11
推荐指数
1
解决办法
5120
查看次数

标签 统计

hidden ×1

python ×1

selenium ×1

xpath ×1