Showing posts with label Element. Show all posts
Showing posts with label Element. Show all posts

Friday, 17 April 2015

What are the different types of Element locators?

The different types of locator are:
  •  ID
  •  Name
  •  Link Text
  •  CSS Selector
  •   Tag and ID
  •   Tag and class
  •   Tag and attribute
  •  Tag, class, and attribute
  •  Inner text
  •   DOM (Document Object Model)
  •   getElementById
  •   getElementsByName
  •   dom:name
  •   dom:index
  •  XPath

There are commands that do not need a locator (such as the "open" command). However, most of them do need Locators.
The choice of locator depends largely on your Application Under Test. In this tutorial we will toggle between facebook , newtours.demoaut on basis of locators that these applications support. Likewise in your testing project you will select any of the above listed locators based on your application support.

Wednesday, 15 April 2015

Which is the best way to locate an element?


Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls down to document.getElementById(), which is optimized by many browsers.

Finding elements by XPath is useful for finding elements using very complex selectors, and is the most flexible selection strategy, but it has the potential to be very slow, particularly in IE. In IE 6, 7, or 8, finding by XPath can be an order of magnitude slower than doing the same in Firefox. IE provides no native XPath-over-HTML solution, so the project must use a JavaScript XPath implementation, and the JavaScript engine in legacy versions of IE really is that much slower.


If you have a need to find an element using a complex selector, I usually recommend using CSS Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases, without exhibiting the extreme performance penalty on IE that XPath can.