javascript - 如何在 Selenium 的 html 标签之间添加文本?

标签 javascript selenium

这是我学习 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/

相关文章:

java - 如何使用 selenium webdriver 和 Java 获取文本框值?

javascript - 如果在初始化函数中分配了事件处理程序,如何传递参数?

javascript - JQuery 自动完成问题

javascript - 有没有javascript库可以帮我操作textarea?

JavaScript 执行器在 Google Chrome 中工作,但在 Firefox 中不起作用

java - 如何从selenium java中的SVG标签内的 "text"标签获取值

javascript - 无法使 javascript 对象属性值更新

javascript - 我如何知道选择框中的可用选项何时更改

maven - 在 Maven Cucumber 报告中构建失败时不会生成报告

selenium - 提交按钮在 Selenium webdriver 中不起作用