【发布时间】:2021-03-05 12:29:17
【问题描述】:
我正在尝试从<div> 中提取文本,这是带有 XPath
<div class="two columns" style="font-size: 18px; padding-top: 5px;">
<img src="images/spins_s.png" border="0" style="margin-bottom: -1px;">
5
</div>
我在这里附上截图, [ https://i.stack.imgur.com/uOmeS.png][1] 当我在 cole 中尝试这个 xpath 表达式时,它的返回 正确的 o/p,
>>$x("//div[@class='two columns']/img[@src='images/spins_s.png']/..")[0].innerText
>>" 5"
但是当我要在python中运行这个代码
spin_balance = browser.find_element_by_xpath("//div[@class='two columns']/img[@src='images/spins_s.png']/..")[0].innerText
它给出了这样的错误
spin_balance = browser.find_element_by_xpath("//div[@class='two columns']/img[@src='images/spins_s.png']/..")[0].innerText
TypeError: 'WebElement' object is not subscriptable
HTML 图像:
【问题讨论】:
标签: python-3.x selenium xpath css-selectors webdriverwait