i have html that looks like this:
<div class=someclass>some text here</div>
can i insert another div into html above with selenium? I've tried doing this with js command execution, but it didn't work, as there are a lot of divs on a page, which have the same class, so I use the xpath to find the div i want
CodePudding user response:
Have you tried something like this?
js = """var node = document.createElement("div");
var textnode = document.createTextNode("Example");
node.appendChild(textnode);
document.getElementById("someIDOnPage").appendChild(node);
"""
driver.execute_script(js)
If you have divs with the same class name just use different ID's. You can do that with JS as well like this:
g = document.createElement('div');
g.setAttribute("id", "Div1");