python - 属性错误: 'WebElement' object has no attribute 'get_text' error extracting the text between the starting and ending tag using Selenium Python

标签 python selenium selenium-webdriver xpath webdriverwait

输入:

<input type="text" name="username" value="TestLeaf" align="left" style="width:350px" xpath="1">
    <div>**TestLeaf**</div>
</input>

Selenium Python 代码:

textGet = driver.find_element_by_xpath("//input[@name='username' and @value='TestLeaf']").get_text
print(textGet)

结果:显示错误

"AttributeError: 'WebElement' object has no attribute 'get_text'"

请帮助我如何在开始和结束标记之间获取文本

最佳答案

要获取文本,只需执行以下操作。

textGet = driver.find_element_by_xpath("//input[@name='username' and @value='TestLeaf']").text

.get_text 不是执行此操作的有效方法。

关于python - 属性错误: 'WebElement' object has no attribute 'get_text' error extracting the text between the starting and ending tag using Selenium Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65121133/

相关文章:

python - 使用scrapy点击网站上的按钮

Python:为什么 int 类没有像 `__lt__()` 这样丰富的比较运算符?

python - tf.train.ExponentialMovingAverage 和 tf.train.MomentumOptimizer 有什么区别?

java - 我需要从列表标签内的 json 脚本获取数据

selenium - 当给定的 xpath 存在多个匹配项时,如何使用 xpath?

java - 获取 Web 表格单元格的颜色

python - 如何使用 Python 和 Selenium WebDriver 获取 localStorage

django - 最大化 django/python 中 selenium webdriver/firefox 驱动程序的页面大小?

python - PyTorch:如何在迁移学习教程中计算均值和标准差?

python - 模块未定义属性/类