SlideShare a Scribd company logo
2
Most read
6
Most read
8
Most read
Selenium With Java 2
Locators
Accessing Forms Elements
• Input Box:
driver.findElement(By.id(“username”)).sendKeys(
“asasya”);
• Radio button
Driver.findElement(By.cssSelector(“input[value=‘
male’]”)).click();
• Check box
WebElement checbox =
driver.findElement(By.id(“persist_box”));
For(int i=0;i<2;i++){
Checkbox.click();
System.out.println(checkbox.isSelected());
Accessing Forms Elements
• Links
driver.findElement(By.linkText(“register
here”)).click();
Or Partial
link text
Locators
• 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
Locators
• ID
Id = email
• Name
Name = username
• Locating by Name using Filters(Filters are additional
attributes used to distinguish elements with the same
name.)
Target Format: name=name_of_the_element
filter=value_of_filter
Ex- name=tripType value=oneway
• Link Text
Target Format: link=link_text
Ex- link = register
Locators
CSS Selector
• Tag and ID
Ex- "css=input#email“
take note that the HTML tag is "input" and its ID is "email".
Note: Keep in mind that the ID is always preceded by a hash
sign (#).
Syntax Description
css=tag#id
•tag = the HTML tag of the element being
accessed
•# = the hash sign. This should always be
present when using a CSS Selector with ID
•id = the ID of the element being accessed
Locators
CSS Selector
• Tag and class
Ex - css=input.inputtext
Take note that when multiple elements have the same
HTML tag and name, only the first element in source
code will be recognized.
Syntax Description
css=tag.class
•tag = the HTML tag of the element being accessed
•. = the dot sign. This should always be present
when using a CSS Selector with class
•class = the class of the element being accessed
Locators
CSS Selector
• Tag and attribute
Ex - css=input[name=lastName]
When multiple elements have the same HTML tag and
attribute, only the first one will be recognized.
Syntax Description
css=tag[attribute=value]
•tag = the HTML tag of the element being
accessed
•[ and ] = square brackets within which a
specific attribute and its corresponding value
will be placed
•attribute = the attribute to be used. It is
advisable to use an attribute that is unique to
the element such as a name or ID.
•value = the corresponding value of the
chosen attribute.
Locators
CSS Selector
Tag, class, and attribute
Syntax Description
css=tag.class[attribute=value]
Ex-
css=input.inputtext[tabindex=1]
•tag = the HTML tag of the element
being accessed
•. = the dot sign. This should always be
present when using a CSS Selector with
class
•class = the class of the element being
accessed
•[ and ] = square brackets within which a
specific attribute and its corresponding
value will be placed
•attribute = the attribute to be used. It is
advisable to use an attribute that is
unique to the element such as a name or
ID.
•value = the corresponding value of the
chosen attribute.
Locators
CSS Selector
Inner text
Syntax Description
css=tag:contains("inner text")
Ex
Ex: css=font:contains("Password:")
•tag = the HTML tag of the
element being accessed
•inner text = the inner text of the
element
Locators
Locating by DOM (Document Object Model)
• getElementById
Syntax Description
document.getElementById("id of the
element")
Ex:
document.getElementById("persist_b
ox")
id of the element = this is the value of
the ID attribute of the element to be
accessed. This value should always
be enclosed in a pair of parentheses
("").
Locators
Locating by DOM (Document Object Model)
• getElementsByName
Syntax Description
document.getElementsByName("name")
[index]
Ex: document.getElementsByName
("servClass")[0]
•name = name of the element as
defined by its 'name' attribute
•index = an integer that indicates
which element within
getElementsByName's array will
be used.
Locators
Locating by DOM (Document Object Model)
• dom:name
• Ex: document.forms["home"].elements["userName"]
Syntax Description
document.forms["name of the
form"].elements["name of the
element"]
•name of the form = the value of the
name attribute of the form tag that
contains the element you want to access
•name of the element = the value of the
name attribute of the element you wish
to access
Locators
Locating by DOM (Document Object Model)
• dom:index
• Ex: document.forms[0].elements[3]
• document.forms[0].elements[“phone”]
Syntax Description
document.forms[index of the
form].elements[index of the
element]
•index of the form = the index number
(starting at 0) of the form with respect to
the whole page
•index of the element = the index
number (starting at 0) of the element
with respect to the whole form that
contains it
Xpath
Xpath
Xpath=//tagname[@attribute='value']
• // : Select current node.
• Tagname: Tagname of the particular node.
• @: Select attribute.
• Attribute: Attribute name of the node.
• Value : Value of the attribute.
Xpath
Xpath locators
Id,classname,Name,Link text, Xpath, CSSpath
Types of X-path
There are two types of XPath:
• 1) Absolute XPath
html/body/div[1]/section/div[1]/div/div/div/div[1]/d
iv/div/div/div/div[3]/div[1]/div/h4[1]/b
2) Relative XPath
Xpath=//*[@id='rt-feature']//parent::div[1]
Xpath=//input[@name='uid']
Reference :
http://www.guru99.com/xpath-selenium.html
Core java
• // indicates a single line comment
• /* begins a comment that must be
terminated with */
• Documentation comments begin with /**
and end with */ . Documentation comments
are used to insert documentation into code.
These comments are then used to produce
documentation by javadoc
Rule
• Package names are written in small letters.
• e.g.: java.io, java.lang, java.awt etc
• · Each word of class name and interface name starts with a
capital
• e.g.: Sample, AddTwoNumbers
• · Method names start with small letters then each word start
with a capital
• e.g.: sum (), sumTwoNumbers (), minValue ()
• · Variable names also follow the same above method rule
• e.g.: sum, count, totalCount
• · Constants should be written using all capital letters
• e.g.: PI, COUNT
• · Keywords are reserved words and are

More Related Content

What's hot (20)

PPTX
Setting up Page Object Model in Automation Framework
valuebound
 
PPTX
Test Automation and Selenium
Karapet Sarkisyan
 
PDF
Automation Testing using Selenium
Naresh Chintalcheru
 
PPTX
Introduction to Selenium Web Driver
Return on Intelligence
 
PPTX
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
PDF
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Edureka!
 
PPTX
Selenium test automation
Srikanth Vuriti
 
PPTX
Unit Testing And Mocking
Joe Wilson
 
PPTX
Selenium introduction
Pankaj Dubey
 
PDF
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
PDF
TestNG Annotations in Selenium | Edureka
Edureka!
 
PPTX
Selenium
Batch2016
 
PPTX
TestNG Framework
Levon Apreyan
 
PDF
Mocking in Java with Mockito
Richard Paul
 
PPTX
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Simplilearn
 
PDF
Web application testing with Selenium
Kerry Buckley
 
PDF
Test Automation Using Python | Edureka
Edureka!
 
PDF
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
PPT
Java Basics for selenium
apoorvams
 
PPTX
QSpiders - Selenium Webdriver
Qspiders - Software Testing Training Institute
 
Setting up Page Object Model in Automation Framework
valuebound
 
Test Automation and Selenium
Karapet Sarkisyan
 
Automation Testing using Selenium
Naresh Chintalcheru
 
Introduction to Selenium Web Driver
Return on Intelligence
 
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Edureka!
 
Selenium test automation
Srikanth Vuriti
 
Unit Testing And Mocking
Joe Wilson
 
Selenium introduction
Pankaj Dubey
 
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
TestNG Annotations in Selenium | Edureka
Edureka!
 
Selenium
Batch2016
 
TestNG Framework
Levon Apreyan
 
Mocking in Java with Mockito
Richard Paul
 
Selenium Tutorial For Beginners | Selenium Automation Testing Tutorial | Sele...
Simplilearn
 
Web application testing with Selenium
Kerry Buckley
 
Test Automation Using Python | Edureka
Edureka!
 
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
Java Basics for selenium
apoorvams
 
QSpiders - Selenium Webdriver
Qspiders - Software Testing Training Institute
 

Similar to Selenium Locators (20)

PPTX
Jquery
Pankaj Srivastava
 
DOCX
ST LAB 15 (1).docx
AfrasAhmad3
 
DOCX
ST LAB 15 (1).docx
AfrasAhmad3
 
PPT
Css
Doeun KOCH
 
PPTX
Html
Sadeek Mohammed
 
PDF
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
PPTX
Css part 1
lokenra
 
PPTX
ppt- u 2.pptx
19ME041NAVEENR
 
PPTX
How to use CSS Selector to identify Web Elements for selenium scripts
Sokunthaneth Chhoy
 
PDF
Intro to JavaScript - Week 4: Object and Array
Jeongbae Oh
 
PPTX
Web technologies-course 11.pptx
Stefan Oprea
 
PPTX
Web Development - Lecture 4
Syed Shahzaib Sohail
 
PDF
Wildcard Selectors in cascading style sheet .pdf
mehakgulzar473
 
PDF
Basic Details of HTML and CSS.pdf
Kalyani Government Engineering College
 
PPT
Lesson 1
Maneesha Caldera
 
PDF
Introduction to jQuery
Zeeshan Khan
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PDF
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
PPTX
It8074 soa-unit i
smitha273566
 
PPTX
PlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Training
 
ST LAB 15 (1).docx
AfrasAhmad3
 
ST LAB 15 (1).docx
AfrasAhmad3
 
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
Css part 1
lokenra
 
ppt- u 2.pptx
19ME041NAVEENR
 
How to use CSS Selector to identify Web Elements for selenium scripts
Sokunthaneth Chhoy
 
Intro to JavaScript - Week 4: Object and Array
Jeongbae Oh
 
Web technologies-course 11.pptx
Stefan Oprea
 
Web Development - Lecture 4
Syed Shahzaib Sohail
 
Wildcard Selectors in cascading style sheet .pdf
mehakgulzar473
 
Basic Details of HTML and CSS.pdf
Kalyani Government Engineering College
 
Introduction to jQuery
Zeeshan Khan
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
It8074 soa-unit i
smitha273566
 
PlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Training
 
Ad

Recently uploaded (20)

PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Ad

Selenium Locators

  • 1. Selenium With Java 2 Locators
  • 2. Accessing Forms Elements • Input Box: driver.findElement(By.id(“username”)).sendKeys( “asasya”); • Radio button Driver.findElement(By.cssSelector(“input[value=‘ male’]”)).click(); • Check box WebElement checbox = driver.findElement(By.id(“persist_box”)); For(int i=0;i<2;i++){ Checkbox.click(); System.out.println(checkbox.isSelected());
  • 3. Accessing Forms Elements • Links driver.findElement(By.linkText(“register here”)).click(); Or Partial link text
  • 4. Locators • 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
  • 5. Locators • ID Id = email • Name Name = username • Locating by Name using Filters(Filters are additional attributes used to distinguish elements with the same name.) Target Format: name=name_of_the_element filter=value_of_filter Ex- name=tripType value=oneway • Link Text Target Format: link=link_text Ex- link = register
  • 6. Locators CSS Selector • Tag and ID Ex- "css=input#email“ take note that the HTML tag is "input" and its ID is "email". Note: Keep in mind that the ID is always preceded by a hash sign (#). Syntax Description css=tag#id •tag = the HTML tag of the element being accessed •# = the hash sign. This should always be present when using a CSS Selector with ID •id = the ID of the element being accessed
  • 7. Locators CSS Selector • Tag and class Ex - css=input.inputtext Take note that when multiple elements have the same HTML tag and name, only the first element in source code will be recognized. Syntax Description css=tag.class •tag = the HTML tag of the element being accessed •. = the dot sign. This should always be present when using a CSS Selector with class •class = the class of the element being accessed
  • 8. Locators CSS Selector • Tag and attribute Ex - css=input[name=lastName] When multiple elements have the same HTML tag and attribute, only the first one will be recognized. Syntax Description css=tag[attribute=value] •tag = the HTML tag of the element being accessed •[ and ] = square brackets within which a specific attribute and its corresponding value will be placed •attribute = the attribute to be used. It is advisable to use an attribute that is unique to the element such as a name or ID. •value = the corresponding value of the chosen attribute.
  • 9. Locators CSS Selector Tag, class, and attribute Syntax Description css=tag.class[attribute=value] Ex- css=input.inputtext[tabindex=1] •tag = the HTML tag of the element being accessed •. = the dot sign. This should always be present when using a CSS Selector with class •class = the class of the element being accessed •[ and ] = square brackets within which a specific attribute and its corresponding value will be placed •attribute = the attribute to be used. It is advisable to use an attribute that is unique to the element such as a name or ID. •value = the corresponding value of the chosen attribute.
  • 10. Locators CSS Selector Inner text Syntax Description css=tag:contains("inner text") Ex Ex: css=font:contains("Password:") •tag = the HTML tag of the element being accessed •inner text = the inner text of the element
  • 11. Locators Locating by DOM (Document Object Model) • getElementById Syntax Description document.getElementById("id of the element") Ex: document.getElementById("persist_b ox") id of the element = this is the value of the ID attribute of the element to be accessed. This value should always be enclosed in a pair of parentheses ("").
  • 12. Locators Locating by DOM (Document Object Model) • getElementsByName Syntax Description document.getElementsByName("name") [index] Ex: document.getElementsByName ("servClass")[0] •name = name of the element as defined by its 'name' attribute •index = an integer that indicates which element within getElementsByName's array will be used.
  • 13. Locators Locating by DOM (Document Object Model) • dom:name • Ex: document.forms["home"].elements["userName"] Syntax Description document.forms["name of the form"].elements["name of the element"] •name of the form = the value of the name attribute of the form tag that contains the element you want to access •name of the element = the value of the name attribute of the element you wish to access
  • 14. Locators Locating by DOM (Document Object Model) • dom:index • Ex: document.forms[0].elements[3] • document.forms[0].elements[“phone”] Syntax Description document.forms[index of the form].elements[index of the element] •index of the form = the index number (starting at 0) of the form with respect to the whole page •index of the element = the index number (starting at 0) of the element with respect to the whole form that contains it
  • 15. Xpath Xpath Xpath=//tagname[@attribute='value'] • // : Select current node. • Tagname: Tagname of the particular node. • @: Select attribute. • Attribute: Attribute name of the node. • Value : Value of the attribute.
  • 16. Xpath Xpath locators Id,classname,Name,Link text, Xpath, CSSpath Types of X-path There are two types of XPath: • 1) Absolute XPath html/body/div[1]/section/div[1]/div/div/div/div[1]/d iv/div/div/div/div[3]/div[1]/div/h4[1]/b 2) Relative XPath Xpath=//*[@id='rt-feature']//parent::div[1] Xpath=//input[@name='uid'] Reference : http://www.guru99.com/xpath-selenium.html
  • 17. Core java • // indicates a single line comment • /* begins a comment that must be terminated with */ • Documentation comments begin with /** and end with */ . Documentation comments are used to insert documentation into code. These comments are then used to produce documentation by javadoc
  • 18. Rule • Package names are written in small letters. • e.g.: java.io, java.lang, java.awt etc • · Each word of class name and interface name starts with a capital • e.g.: Sample, AddTwoNumbers • · Method names start with small letters then each word start with a capital • e.g.: sum (), sumTwoNumbers (), minValue () • · Variable names also follow the same above method rule • e.g.: sum, count, totalCount • · Constants should be written using all capital letters • e.g.: PI, COUNT • · Keywords are reserved words and are