An Overview of Frequently Used Methods

As we mentioned in the first chapter, Selenium WebDriver is an API that allows for automating browser activity.


Updated information about the class can always be found at https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.html.

The following list provides descriptions of the most frequently used methods of the WebDriver class:

  • void close(): This closes the current window and exits the browser (if it's the last window currently open).
  • WebElement findElement(By by): This receives search parameters and returns the first matching element on the current page, or NoSuchElementException if no element is found. We will cover this subject in detail in upcoming chapters.
  • java.util.List<WebElement> findElements(By by): This receives search parameters and returns all of the matching elements on the current page, or an empty list if no element is found. We will cover this subject in detail in upcoming chapters.
  • void get(java.lang.String url): This loads the received URL in the current browser window. It is used to indicate and load the web application that we want to test.
  • java.lang.String getCurrentUrl(): This returns the URL of the current browser.
  • java.lang.String getPageSource(): This returns the source of the last loaded page. Depending on the driver being used, if the page is modified after having been loaded, the returned source might not correspond to the modified page.
  • java.lang.String getTitle(): This returns the title of the current page, or null if one has not been set. It is normally used to verify that we are working in the correct window during a test.
  • WebDriver.Options manage(): This returns the interface option of the menu. For example, it allows for the management of cookies (add, delete, and get).
  • void quit(): This quits the driver and closes all associated windows. It is the preferred method to end an automation script.

You should now have a better understanding of the most frequently used methods of the WebDriver class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.160.216