To Remove the web element in the webpage during selenium execution:
Lets consider this :
Here I want to remove the footer from the webpage while executing and then take a screenshot without the footer.
Method to execute the javascript in the webpage
Method.java
public static void javaScriptExecutor(String javaScript){ JavascriptExecutor js=null; if (driver instanceof JavascriptExecutor) { js = (JavascriptExecutor)driver; } js.executeScript(javaScript);}
Sample.java
//code whatever you want
Method.javaScriptExecutor("document.getElementsByClassName('footer')[0].style.display
= \"none\";");
Change the class name as per your requirement.
After this code is executed, the footer is removed.