如何设置<pre> html tag using Selenium Java?

时间:2016-12-29 19:59:49

标签: java selenium

I tried using sendKeys() method on webelement but it does not work. Does anyone has any idea if this can be achieved ?

Please find below the html.

<div class="CodeMirror-code" style="">
 <div style="position: relative;">
 <div style="position: absolute; left: -51px;">
 **<pre>**
</pre>
</div>
</div>
</div>

1 个答案:

答案 0 :(得分:1)

请尝试以下代码:

JavascriptExecutor js = (JavascriptExecutor) driver;
      WebElement element = driver.findElement(By.xpath('//div[@class="CodeMirror-code"]//p'));
      js.executeScript('arguments[0].innerHTML = "text goes here";', element);