SlideShare una empresa de Scribd logo
1 de 11
Locators in Selenium
Presented By
Dwarika Dhish Mishra
Email : dwarika1987@gmail.com
Mob: 9999978609
Blog: http://abodeqa.wordpress.com
What are locators?
Locators are a way to tell selenium which specific element
we want it to act on
Locators used:
• Id
• Name
• Class
• Tag
• linkText
• Xpath
• CSSLocator
Finding Element By Id
• Id attribute is most preferred way to locate element on a
webpage, since as per W3C standard every element should
have a unique Id so that It could be indentified uniquely
<form name="loginForm">
<label for="username">UserName: </label> <input
type="text"
id="username" /><br/>
<label for="password">Password: </label> <input
type="password" id="password" /><br/>
<input name="login" type="submit" value="Login" />
</form>
Finding Element By Id
So to perform action on Username and
Password in Selenium WebDriver we need
write this line of code
WebElement username = driver.findElement(By.Id(“username”));
WebElement username = driver.findElement(By.Id(“password”));
Finding Element by Name
<form name="loginForm">
<label for="username">UserName: </label>
<input type="text”name="username" /><br/>
<label for="password">Password: </label>
<input type="password" name="password" /><br/>
<input name="login" type="submit" value="Login" />
</form>
Finding Element by Name
Since in some situations we don’t have Id
attribute provided in HTML so in that case we
use some other attribute like name and Class
and Tagname
So Line of code that we need to use
WebElement username = driver.findElement(By.Name(“username”));
WebElement username = driver.findElement(By.Name(“password”));
Find Element by Xpath
• Using Direct Xpath
Like /html/body/Element
• Using nth of type
• Using attribute
Like //input*@name=‘username’+
• Using partial match by using contain()
function
//input[Contains(@name,’user’)+
Continue…
• Pattern matching using starts-with() function
$x("//input[starts-with(@id,‘us')]")
• Pattern matching using ends-with() function
$x("//input[ends-with(@id,‘name')]")
• Finding element using substring() function
when we are dealing with some dynamic
element
$x("//input[substring(@id,3)='ername']")
Continue…
• Axis method
– following-sibling::HTML tag
Like $x("//input[substring(@id,3)='ername']/followingsibling::input[@id='password']")
Or
$x("//input[substring(@id,3,5)='ernam']/followingsibling::input[@id='password']")
– preceding-sibling::HTML tag
– using ‘..’ to navigate to parent
$x("//input[substring(@id,3)='ername']/..")
Coming session topic
-CSS Locator
- Launching Chrome Browser /Firefox Browser/IE Browser
- Testng framework and its annotation used in Selenium
Thank you !!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium Automation Framework
Selenium Automation  FrameworkSelenium Automation  Framework
Selenium Automation Framework
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium
SeleniumSelenium
Selenium
 
Automation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverAutomation Testing using Selenium Webdriver
Automation Testing using Selenium Webdriver
 
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
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Selenium cheat sheet
Selenium cheat sheetSelenium cheat sheet
Selenium cheat sheet
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
SELENIUM PPT.pdf
SELENIUM PPT.pdfSELENIUM PPT.pdf
SELENIUM PPT.pdf
 
Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch  Step by step - Selenium 3 web-driver - From Scratch
Step by step - Selenium 3 web-driver - From Scratch
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
 

Similar a Locators in selenium - BNT 09

2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6
Marakana Inc.
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014
Mark Rackley
 

Similar a Locators in selenium - BNT 09 (20)

Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with Java
 
Css selector - BNT 11
Css selector - BNT 11 Css selector - BNT 11
Css selector - BNT 11
 
2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docx
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docx
 
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
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014
 
Selenium再入門
Selenium再入門Selenium再入門
Selenium再入門
 
Search driven architecture in SharePoint
Search driven architecture in SharePointSearch driven architecture in SharePoint
Search driven architecture in SharePoint
 
CSS Selector in Selenium WebDriver | Edureka
CSS Selector in Selenium WebDriver | EdurekaCSS Selector in Selenium WebDriver | Edureka
CSS Selector in Selenium WebDriver | Edureka
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
 
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
 
Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1
 
Locator strategy for web elements | Katalon Studio
Locator strategy for web elements | Katalon StudioLocator strategy for web elements | Katalon Studio
Locator strategy for web elements | Katalon Studio
 
Web testing with selenium and by quontra solutions
Web testing with selenium and  by quontra solutionsWeb testing with selenium and  by quontra solutions
Web testing with selenium and by quontra solutions
 
Don't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQueryDon't Worry jQuery is very Easy:Learning Tips For jQuery
Don't Worry jQuery is very Easy:Learning Tips For jQuery
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
 
The SharePoint & jQuery Guide
The SharePoint & jQuery GuideThe SharePoint & jQuery Guide
The SharePoint & jQuery Guide
 
The SharePoint and jQuery Guide by Mark Rackley - SPTechCon
The SharePoint and jQuery Guide by Mark Rackley - SPTechConThe SharePoint and jQuery Guide by Mark Rackley - SPTechCon
The SharePoint and jQuery Guide by Mark Rackley - SPTechCon
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Locators in selenium - BNT 09

  • 1. Locators in Selenium Presented By Dwarika Dhish Mishra Email : dwarika1987@gmail.com Mob: 9999978609 Blog: http://abodeqa.wordpress.com
  • 2. What are locators? Locators are a way to tell selenium which specific element we want it to act on Locators used: • Id • Name • Class • Tag • linkText • Xpath • CSSLocator
  • 3. Finding Element By Id • Id attribute is most preferred way to locate element on a webpage, since as per W3C standard every element should have a unique Id so that It could be indentified uniquely <form name="loginForm"> <label for="username">UserName: </label> <input type="text" id="username" /><br/> <label for="password">Password: </label> <input type="password" id="password" /><br/> <input name="login" type="submit" value="Login" /> </form>
  • 4. Finding Element By Id So to perform action on Username and Password in Selenium WebDriver we need write this line of code WebElement username = driver.findElement(By.Id(“username”)); WebElement username = driver.findElement(By.Id(“password”));
  • 5. Finding Element by Name <form name="loginForm"> <label for="username">UserName: </label> <input type="text”name="username" /><br/> <label for="password">Password: </label> <input type="password" name="password" /><br/> <input name="login" type="submit" value="Login" /> </form>
  • 6. Finding Element by Name Since in some situations we don’t have Id attribute provided in HTML so in that case we use some other attribute like name and Class and Tagname So Line of code that we need to use WebElement username = driver.findElement(By.Name(“username”)); WebElement username = driver.findElement(By.Name(“password”));
  • 7. Find Element by Xpath • Using Direct Xpath Like /html/body/Element • Using nth of type • Using attribute Like //input*@name=‘username’+ • Using partial match by using contain() function //input[Contains(@name,’user’)+
  • 8. Continue… • Pattern matching using starts-with() function $x("//input[starts-with(@id,‘us')]") • Pattern matching using ends-with() function $x("//input[ends-with(@id,‘name')]") • Finding element using substring() function when we are dealing with some dynamic element $x("//input[substring(@id,3)='ername']")
  • 9. Continue… • Axis method – following-sibling::HTML tag Like $x("//input[substring(@id,3)='ername']/followingsibling::input[@id='password']") Or $x("//input[substring(@id,3,5)='ernam']/followingsibling::input[@id='password']") – preceding-sibling::HTML tag – using ‘..’ to navigate to parent $x("//input[substring(@id,3)='ername']/..")
  • 10. Coming session topic -CSS Locator - Launching Chrome Browser /Firefox Browser/IE Browser - Testng framework and its annotation used in Selenium

Notas del editor

  1. Reference:W3schools.com