1

I would like to change the html of an webpage and add an element.

Before: div p something /p /div

After: div form p something /p /form /div

Is this possible? Would be very happy, if someone answers. Thank you.

1 Answers1

1

You can modify the page with js, just use the execute_script function of your web driver in Selenium, modifying the DOM to insert whatever you want wherever you want in JS:

js = """var node = document.createElement("div");
var textnode = document.createTextNode("Example");
node.appendChild(textnode);
document.getElementById("someIDOnPage").appendChild(node);  
"""
driver.execute_script(js)
TheoretiCAL
  • 19,461
  • 8
  • 43
  • 65