输入:
<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/