【发布时间】:2015-05-13 01:18:00
【问题描述】:
以下
element = driver.execute_script("return $('.theelementclass')")[0]
找到我的元素(一个只包含一些文本的 div),但是:
element.text
返回一个空字符串(这是一个惊喜)。从 Java 脚本控制台:
$('.theelementclass').text # also (consistently) empty
$('.theelementclass').innerText # YES! gets the div's text.
所以,我的问题是,鉴于我有一些 WebElement,我可以找到 innerText 吗? (出于无聊的原因,我想使用找到的 web 元素进行操作,而不是原始查询)。
我包括周围的 HTML。但是,我认为它没有用(因为元素被发现并且是唯一的)
<first-panel on-click="onClickLearnMore()" class="ng-isolate-scope">
<div class="comp-onboarding-first-thought-panel">
<div class="onboarding-text-container">
<div class="theelementclass">
Congratulations.
You found the text is here!
</div>
<div class="button-cont">
<div ng-click="onClickButton()">Learn more about The Thing</div>
</div>
</div>
</div>
</first-panel>
【问题讨论】:
-
你能添加你试图从中获取文本的 HTML 吗?
-
它是否适用于 element.get_attribute('innerText')?您也可以尝试使用 element.get_attribute('innerHTML')。您使用的是什么浏览器驱动程序(firefox、chrome 等)?