开发者

WebDriver: add new element

开发者 https://www.devze.com 2023-01-24 19:24 出处:网络
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

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

精彩评论

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