Modify innerHTML using Selenium Modify innerHTML using Selenium selenium selenium

Modify innerHTML using Selenium


Try this:

WebElement element = ...((JavascriptExecutor)driver).executeScript(  "var ele=arguments[0]; ele.innerHTML = 'my new content';", element);


Selenium WebDriver does not have any direct methods to do so to change the DOM itself. However we can use JavascriptExecutor to use javascript to modify the DOM.

check this example to change the background color. You will get an idea to change the innerHTML as well.


in python use this :

element = driver.find_element_by_id("some_id")driver.execute_script("arguments[0].innerText = 'what_you_want_to_show'", element)