这是我学习硒的第二天。我想在称为的这些html标签之间提取文本。
HTML代码示例:
<div id="media-buttons" class="hide-if-no-js"/>
<textarea id="DescpRaw" class="ckeditor" name="DescpRaw" rows="13" cols="100" style="visibility: hidden; display: none;">
Cactus spines are produced from specialized structures
called areoles, a kind of highly reduced branch. Areoles
are an identifying feature of cacti.
</textarea>
</div>
所需结果:
Cactus spines are produced from specialized structures
called areoles, a kind of highly reduced branch. Areoles
are an identifying feature of cacti.
我已经尝试过下面的Selenium驱动程序,但是它是空的。
String bodyhtml = driver.findElement(By.xpath("//textarea[@name='DescpRaw']")).getText();
谢谢!
最佳答案
String bodyhtml = driver.findElement(By.xpath("//textarea[@name='DescpRaw']")).getAttribute("innerHTML");
我也建议使用ID,因为它可用并且速度更快。
String bodyhtml = driver.findElement(By.id("DescpRaw")).getAttribute("innerHTML");