开发者

WebDriver: add new element

Is there a method to add/insert an element in the开发者_JS百科 current DOM?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜