Learning Selenium Testing Tools(Third Edition)
上QQ阅读APP看书,第一时间看更新

Summary

We learnt a lot in this chapter about locators. We were able to use a large number of different methods to find the elements that are on a page. We saw how to find elements using easy methods such as id=, name= to find elements and running queries against the DOM to find them using CSS selectors or XPath queries.

Specifically, we covered the following topics:

  • Using Firebug to find element attributes: In this section, we were able to start using Firebug. This will become an invaluable tool for anyone who works with web applications. It has a very good mechanism for finding elements so that you can work against them.
  • Finding an element by ID: Elements can easily be found by the value of the ID attribute. This is the most common way to find elements and is the fastest way to find the elements on the page.
  • Finding an element by name: When elements do not have IDs but do have a name attribute, your tests can use them.
  • Finding an element by DOM query: In this section, we were able to use the power of JavaScript DOM API calls to find the element that we wish to work with. This can be from the most basic call to the document to a JavaScript function that you can pass variables to.
  • Finding an element using XPath queries: In this section, we were able to find the element on the page by using XPath queries. Your test can use relative paths or even XPath functions to find the element on the page. The queries can be as complex as you want, but remember that they can impact the speed of the test.
  • Finding an element using CSS selectors: When XPath queries slow down your tests, especially in browsers that do not have good support for XPath, CSS selectors are starting to become the default way to find elements on web pages with popular JavaScript libraries, and there is not a large.

We also discussed how XPath queries can make tests run slower on browsers that do not have native XPath support. Microsoft IE is the main browser where you will see this issue. When tests start running extremely slowly with XPath, we can move our tests over to CSS to see large speed gains in our tests.

If a locator does not have a locator type identifier in front of it, Selenium will default to the following strategies:

  • DOM: For locators starting with a document
  • XPath: For locators starting with //
  • Identifier: For any other locator using the ID and name of the element

Now that we've learnt how to locate elements on the page, we're ready to learn how WebDriver is made up, which is the topic of the next chapter.

The summary of locators used in Selenium IDE: