这是我学习 Selenium 的第二天。我想提取这些名为 的 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");
关于javascript - 如何在 Selenium 的 html 标签之间添加文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45245788/