SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Locators in selenium - BNT 09
Locators in selenium - BNT 09Locators in selenium - BNT 09
Locators in selenium - BNT 09
weekendtesting
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
Aneesh Rangarajan
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
Anirudh Raja
 
Selenium Concepts
Selenium ConceptsSelenium Concepts
Selenium Concepts
Swati Bansal
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
Return on Intelligence
 
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaWhat is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
Edureka!
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
Pavan Kumar
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
Kerry Buckley
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
Tzirla Rozental
 
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Edureka!
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
Hassan Dar
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
Md. Mahedee Hasan
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - Introduction
Amr E. Mohamed
 
Selenium
SeleniumSelenium
Selenium
Adam Goucher
 
Selenium
SeleniumSelenium
Selenium
Batch2016
 
Types of test tools
Types of test toolsTypes of test tools
Types of test tools
Vaibhav Dash
 
Dom
DomDom
Dom
Rakshita Upadhyay
 
Python selenium
Python seleniumPython selenium
Python selenium
Ducat
 
Locators in selenium - BNT 09
Locators in selenium - BNT 09Locators in selenium - BNT 09
Locators in selenium - BNT 09
weekendtesting
 
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | EdurekaWhat is WebElement in Selenium | Web Elements & Element Locators | Edureka
What is WebElement in Selenium | Web Elements & Element Locators | Edureka
Edureka!
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
Kerry Buckley
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
Tzirla Rozental
 
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Edureka!
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
Hassan Dar
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - Introduction
Amr E. Mohamed
 
Types of test tools
Types of test toolsTypes of test tools
Types of test tools
Vaibhav Dash
 
Python selenium
Python seleniumPython selenium
Python selenium
Ducat
 

Similar to Selenium Locators (20)

Jquery
JqueryJquery
Jquery
Pankaj Srivastava
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docx
AfrasAhmad3
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docx
AfrasAhmad3
 
Css
CssCss
Css
Doeun KOCH
 
Html
HtmlHtml
Html
Sadeek Mohammed
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
Css part 1
Css part 1Css part 1
Css part 1
lokenra
 
ppt- u 2.pptx
ppt- u 2.pptxppt- u 2.pptx
ppt- u 2.pptx
19ME041NAVEENR
 
How to use CSS Selector to identify Web Elements for selenium scripts
How to use CSS Selector to identify Web Elements for selenium scriptsHow to use CSS Selector to identify Web Elements for selenium scripts
How to use CSS Selector to identify Web Elements for selenium scripts
Sokunthaneth Chhoy
 
Intro to JavaScript - Week 4: Object and Array
Intro to JavaScript - Week 4: Object and ArrayIntro to JavaScript - Week 4: Object and Array
Intro to JavaScript - Week 4: Object and Array
Jeongbae Oh
 
Web technologies-course 11.pptx
Web technologies-course 11.pptxWeb technologies-course 11.pptx
Web technologies-course 11.pptx
Stefan Oprea
 
Web Development - Lecture 4
Web Development - Lecture 4Web Development - Lecture 4
Web Development - Lecture 4
Syed Shahzaib Sohail
 
Basic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdfBasic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdf
Kalyani Government Engineering College
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
Maneesha Caldera
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Zeeshan Khan
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
smitha273566
 
PlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Automation Training Hyderabad | Best Course.pptxPlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Training
 
CSS
CSSCSS
CSS
Akila Iroshan
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docx
AfrasAhmad3
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docx
AfrasAhmad3
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
Css part 1
Css part 1Css part 1
Css part 1
lokenra
 
How to use CSS Selector to identify Web Elements for selenium scripts
How to use CSS Selector to identify Web Elements for selenium scriptsHow to use CSS Selector to identify Web Elements for selenium scripts
How to use CSS Selector to identify Web Elements for selenium scripts
Sokunthaneth Chhoy
 
Intro to JavaScript - Week 4: Object and Array
Intro to JavaScript - Week 4: Object and ArrayIntro to JavaScript - Week 4: Object and Array
Intro to JavaScript - Week 4: Object and Array
Jeongbae Oh
 
Web technologies-course 11.pptx
Web technologies-course 11.pptxWeb technologies-course 11.pptx
Web technologies-course 11.pptx
Stefan Oprea
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Zeeshan Khan
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
RAVALCHIRAG1
 
PlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Automation Training Hyderabad | Best Course.pptxPlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Automation Training Hyderabad | Best Course.pptx
PlayWright Training
 
Ad

Recently uploaded (20)

GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
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