Remove an web-element from the page during runtime


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.





Convert resultset object to list of map

Convert the resultset object to list of map In some cases, while we doing API automation, we need to fetch the value from the DB and hav...