Friday, 22 April 2016

Selenium WebDriver

Selenium WebDriver API Commands And Operations

Fetching a page

              You can navigate from one page to another page by just calling a get method
  •                  driver.get("http://www.google.com");
Dependent on several factors, including the OS/Browser combination, WebDriver may or may not wait for the page to load. In some circumstances, WebDriver may return control before the page has finished, or even started, loading. To ensure robustness, you need to wait for the element(s) to exist in the page using explicit or implicit wait.

Locating Web Elements or UI Elements


Locating elements in WebDriver can be done on the WebDriver instance itself or on a WebElement. Each of the language bindings expose a “Find Element” and “Find Elements” method. The first returns a WebElement object otherwise it throws an exception. The latter returns a list of WebElements, it can return an empty list if no DOM elements match the query.

The “Find” methods take a locator or query object called “By”. “By” strategies are listed below.

By ID

Example of how to find an element that looks like this:
  •               <div id="coolestWidgetEvah">...</div>             
  • webElement Element=driver.findElement(By.id("coolestWidgetEvah"));
This is the most efficient and preferred way to locate an element. Common pitfalls that UI developers make is having non-unique id’s on a page or auto-generating the id, both should be avoided. A class on an html element is more appropriate than an auto-generated id.

3 comments:

  1. My friend Suggest me this blog and I can say this is the best blog to get the basic knowledge.Thank you so much for this Selenium Training in Chennai blog

    ReplyDelete
  2. Best blog.Got to learn new things.Thanks for this Blog SAP HR Training in Chennai

    ReplyDelete
  3. Great place to learn about the new things and got great knowledgeSAP MM Training in Chennai

    ReplyDelete