Interview Questions, Answers and Tutorials

19.2 WebDriver browser methods

19.2 WebDriver browser methods

getWindowHandles
19.2.1| getPageSource

Returns the page source of the last loaded page. The page source returned is a representation of the underlying DOM. It may not be formatted or escaped in the same way as the response sent from the server.

                                                                                                                                                      
      Syntex               java.lang.String getPageSource
      parameters            
      returns              The page source of the current page

                                                                                                                                            

Write a code to open testinganswers.com and retrieve its page source

getPageSource in selenium



Note: If the page is modified after page reload (e.g. page refresh after selecting some list box option), then there is no guarantee that the returned page source text is of the reloaded page. WebDriver documentation can be referenced to know the exact behavior of the specific driver.


19.2.2| navigate

Simulates browser back, forward, refresh and navigate to options.

                                                                                                                                                      
      Syntex               WebDriver.Navigation navigate()
      parameters            
      returns              A WebDriver.Navigation that allows the 
                           selection of what to do next

                                                                                                                                            

This method allows WebDriver test script to simulate user interactions with browsers such as navigating to specific URL, clicking on browser back or forward button, clicking on browser refresh button, etc. 

Navigate browser

 


19.2.3| getWindowHandles

Returns all browser windows of the WebDriver instance.

                                                                                                                                                      
      Syntex               java.util.Set<java.lang.String>
      parameters            
      returns              A set of window handles that can be used to iterate over all the open                                   windows.

                                                                                                                                            

Suppose the user opens testinganswers.com and then clicks on the link available on the site in another/ new window. So, see how to handle all windows and perform an action on all the windows (Driver instances) in Selenium.

getWindowHandles

 
 

19.2.4| getWindowHandle

Returns the currently active browser window of the WebDriver instance.

                                                                                                                                                      
      Syntex               java.lang.String getWindowHandle()
      parameters            
      returns              Returns the currently active window
                           handle. 

                                                                                                                                                  

Suppose the user opens testinganswers.com and then clicks on the link available on the site in another/ new window. So, see how to handle both windows and perform an action on both windows (Driver instances) in Selenium.

getWindowHandle in Selenium

 

 
Answer Here…

4 thoughts on “19.2 WebDriver browser methods

  1. It's very useful article with inforamtive and insightful content and i had good experience with this information. We, at the CRS info solutions ,help candidates in acquiring certificates, master interview questions, and prepare brilliant resumes.Go through some helpful and rich content Salesforce Admin syllabus from learn in real time team. This Salesforce Development syllabus is 100% practical and highly worth reading. Recently i have gone through Salesforce Development syllabus and Salesforce Admin syllabus which includes Salesforce training in USA so practically designed.

Comments are closed.