Upload
dharmesh-vaya
View
107
Download
2
Embed Size (px)
Citation preview
Hands-on guide toObject Identification
Speaker : Dharmesh VayaPresented On : 24.06.2016Twitter : @DRVayaWeb : http://drvaya.wordpress.com/
Test Automation Consultant with 10+ yrs experience
Expertise with designing/development of Selenium based Automation frameworks (as well as other tools)
Speaker at various forums - Google DevFests, Selenium Conference
Trainer/Mentor - to different MNCs/Startups.
Dharmesh Vayaa.k.a.
Dharam
Agenda
★ Basics of Object Identification
★ What are CSS Selectors/Locator’s ?
★ What are Xpath Locators ?
★ Let’s go advanced …
★ Cheat Sheet
★ Best Practices from experience
Basics ofObject Identification
Approach ...★ More than locators you need to understand the underlying
Web development techniques.
★ Carefully understand the page source and identify the libraries
used. This will help in building robust scripts.
★ Using Firebug/Developer tools.
★ Test your element even before you do it with Selenium.
(Developer toolbars are meant for that).
★ Ultimately, Locators come first, Logic is secondary and will be
built upon the locators.
What areCSS Selectors/Locator’s?
CSS Selectors...
★ Absolute SelectorsWorld -> Continent -> Country -> State -> City -> Street
★ Relative SelectorsStreet Number or House Number
★ Class or ID based Selectors
★ Finding using other attributes
★ Partial Matching
What areXpath Locator’s ?
Xpath Locators...
★ Absolute XpathWorld -> Continent -> Country -> State -> City -> Street
★ Relative XpathStreet Number or House Number
★ Index based Xpath
★ Finding using other attributes
★ Partial Matching
Let’s go advanced..
Complex Selectors
★ Partial Matching
Description CSS Xpath
Starting with ^= starts-with()
Ending with $= ends-with()
Contains *= contains()
Few more, Complex Selectors
★ Elements based on relationships
Xpath : ancestor, descendent, preceding, following
CSS: :first-child, :last-child, :nth-child(n)
★ Based on UI state
CSS: enabled, disabled, checked, :not()
Cheat Sheet
Handy Reference for CSS/XpathApproach Description/HTML CSS Xpath
Finding by ID <input id='user'> input#user //input[@id='user']
Finding by Class <input class='user'> input.user //input[@class='user']
Any attribute <input name='text'> input[name='text'] //input[@name='text']
Direct Child <ul> has several <li> ul > li //ul/li
Any Child/Grandchild <ul> has several <li> ul li //ul//li
nth-child 4th <li> from <ul> ul li:nth-of-type(4) //ul/li[4]
Direct Parent <ul> is parent of <li class='active'> li.active:parent //li[@class='active']/..
Next Sibling 2nd <li> tag from several <li> tags li.active + li //li[@class='active']/../li[2]
By Text Link with Sign In text a:contains('Sign In') //a[contains(text(), 'Sign In')]
Best Practices from Experience
Make scripts more robust...
★ Avoid fragile selectors like ones having numbers or text that
appears to be variable
★ Don’t rely on a hierarchy of elements above 3-4 levels
★ Avoid using more than 2 attributes for a composite selector
★ Ensure the selectors in all browsers using the console
★ Store Element locators outside your classes … Excel/XML/Text
anywhere but not in your code.
★ At times, you may avoid GUI automation too !!!
Happy to answer any questions/queries related to Automation testing …..
Slides will be available on -
http://drvaya.wordpress.com/