JavaScriptExecutor in Selenium

JavaScriptExecutor is an interface which provides mechanism to execute Javascript through selenium driver. It provides “executescript” & "executeAsyncScript" methods, to run JavaScript in the context of the currently selected frame or window.
JavaScriptExecutor is an interface which provides mechanism to execute Javascript through selenium driver. It provides “executescript” & "executeAsyncScript" methods, to run JavaScript in the context of the currently selected frame or window.
  • script - The JavaScript to execute
  • Arguments - The arguments to the script.(Optional)
  • 1.How to generate Alert Pop window in selenium?
  • Code:-

  • 2.How to click a button in Selenium WebDriver using JavaScript
  • Code:-

  • 3.How to refresh browser window using Javascript ?
  • Code:-

  • 4.How to get innertext of the entire webpage in Selenium?
  • Code:-

  • 5.How to get the Title of our webpage ?
  • Code:-

  • 6.How to perform Scroll on application using Selenium
  • Code:-

    Note:- for scrolling till the bottom of the page we can use the code like
    js.executeScript("window.scrollBy(0,document.body.scrollHeight)");

  • 7.How to click on a SubMenu which is only visible on mouse hover on Menu?
  • Code:-

  • 8.Implement Highlight in Selenium?
  • 9.How to navigate to different page using Javascript?
  • Code:-

  • Working Demo:-
  • Code:-