19.1 WebDriver browser methods

WebDriver provides a variety of methods to simulate user actions on a browser. Some of those methods are described below 

19.1.1| get


Loads a new page in the current browser window. This is achieved using HTTP GET operation. This method blocks the WebDriver test execution until the page load is complete.


                                                                                                                                                             
            Syntex               get (java.lang.String URL)
      parameter            URL   - URL of the site to navigate to
      returns              void
                                                                                                                                                       


Write WebDriver code to open the Chrome browser and navigate to the https://www.testinganswers.com site

get



19.1.2| getCurrentUrl

Returns the current URL of the browser page

                                                                                                                                                           
            Syntex         java.lang.String getCurrentUrl
      parameter            
      returns        URL of the page currently loaded in the 
                     browser
                                                                                                                                                       


Write WebDriver code to open the Chrome browser, navigate to the https://www.testinganswers.com site and then verify that the current page is testinganswers.com or not.


getCurrentUrl


19.1.3| getTitle

Returns the title of the current web page

                                                                                                                                                          
            Syntex         java.lang.String getTitle
      parameter            
      returns        the title of the current web page with 
                     leading and trailing whitespace stripped or
                     null if one is not already set.
                                                                                                                                                       


Write WebDriver code to open the Chrome browser, navigate to the https://www.testinganswers.com site and then verify that the current page title is correct or not.


getTitle


19.1.4| findElements


Finds all the matched elements on the current page. This method continuously tries to identify the elements till zero or more elements are found or timeout time is reached, whichever happens first.

                                                                                                                                                          
            Syntex         java.util.List<WebElement> findElements(By by)
      parameter      by - the locating mechanism to use      
      returns        the list of all matched elements or an empty
                     list if no match is found.
                                                                                                                                                       

Find all-day elements of a calendar.


Find all-day elements of a calendar.










19.1.5| findElement


Finds the first matched web element on the current page. This method continuously tries to identify the elements until the element is found or timeout time is reached, whichever happens first. If no matched element is found until timeout time, then it returns an exception. This method implicitly waits to identify the element until the configured timeout is reached.

                                                                                                                                                          
            Syntex         WebElement findElement(By by)
      parameter      by - the locating mechanism to use      
      returns        the first matched elements else throws 
                     NoSuchElementException if no matched element
                     found
                                                                                                                                                       

Select an element from the calendar year drop-down.


No comments: