We can replace inner html of any element existing on the page.
To do this we should use JavascriptExecutor
and execute a script.
In general Java code looks just like this
Modify text of element
Let’s try to implement this 2 steps scenario with Selenium WebDriver
1. Get to www.google.com
2. Replace the Gmail link’s text (top-right corner) with Hotmail
What links/pages on the Internet would you modify? :)
Replace page’s content
Using the same approach we can replace the content of the page with html from a file. Let’s implement that.
The file should be saved in the resources
folder.
Note: See How to read file to String
You may also find these posts interesting: