Is there a method to add/insert an element in the current DOM?
Asked
Active
Viewed 9,297 times
1 Answers
7
Let me start by saying, this is a really bad idea. Think long and hard about why you want to do this. Then, if you still want to dynamically add elements, think about it some more. WebDriver is meant to mimic user interaction with your page, users don't typically add elements willy-nilly.
That said, if you're absolutely set on doing this I'd suggest using the JavascriptExecutor to add an element via JavaScript
WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('myDiv').appendChild(document.createTextNode(' New Element'))")
It's ugly for a reason.

pnewhook
- 4,048
- 2
- 31
- 49
-
Isnt it IJavaScriptExecutor? – Anders Lindén May 19 '16 at 12:40