我怎么能得到变量的文本从这个html?



我试图从这个html中获得文本类型('14')作为变量

<div class="hale_sup"></div>
<button class="hale" aria-disabled="true" type="button" disabled="" aria-label="Previous page"></button>
<div class="hale_2"><input tabindex="0" type="text" size="2" aria-label="Current page" value="1"></div>
'of'
'14'

我试图获取文本('14')

text = driver.find_element(By.XPATH,"//div [@class='hale_sup']/text()[1]")

我得到这个错误:xpath表达式的结果是:[object Text]。它应该是一个元素

我也试过了:

driver.find_element(By.XPATH,"//div [@class='hale_sup']").text().

为了获得同时出现的文本

'str' object is not callable

Text是一个属性,不是一个函数,你可以尝试:

print(driver.find_element(By.XPATH,"//div [@class='hale_sup']/..").text)

最新更新