SlideShare ist ein Scribd-Unternehmen logo
1 von 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 !!

Weitere ähnliche Inhalte

Was ist angesagt?

Test Automation Using Python | Edureka
Test Automation Using Python | EdurekaTest Automation Using Python | Edureka
Test Automation Using Python | EdurekaEdureka!
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with seleniumTzirla Rozental
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react formYao Nien Chung
 
Selenium test automation
Selenium test automationSelenium test automation
Selenium test automationSrikanth Vuriti
 
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 Frameworkvaluebound
 
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 SeleniumKerry Buckley
 
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...Edureka!
 
Automation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverAutomation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverPankaj Biswas
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Edureka!
 
Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with JavaFayis-QA
 
Introduction to Selenium Automation
Introduction to Selenium AutomationIntroduction to Selenium Automation
Introduction to Selenium AutomationMindfire Solutions
 

Was ist angesagt? (20)

Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
 
Selenium Concepts
Selenium ConceptsSelenium Concepts
Selenium Concepts
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Test Automation Using Python | Edureka
Test Automation Using Python | EdurekaTest Automation Using Python | Edureka
Test Automation Using Python | Edureka
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
 
Selenium
SeleniumSelenium
Selenium
 
Selenium test automation
Selenium test automationSelenium test automation
Selenium test automation
 
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
 
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
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
 
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
 
Automation Testing using Selenium Webdriver
Automation Testing using Selenium WebdriverAutomation Testing using Selenium Webdriver
Automation Testing using Selenium Webdriver
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
Selenium WebDriver Tutorial For Beginners | What Is Selenium WebDriver | Sele...
 
Html forms
Html formsHtml forms
Html forms
 
Selenium
SeleniumSelenium
Selenium
 
Selenium WebDriver with Java
Selenium WebDriver with JavaSelenium WebDriver with Java
Selenium WebDriver with Java
 
Introduction to Selenium Automation
Introduction to Selenium AutomationIntroduction to Selenium Automation
Introduction to Selenium Automation
 

Ähnlich wie Locators in selenium - BNT 09

Css selector - BNT 11
Css selector - BNT 11 Css selector - BNT 11
Css selector - BNT 11 weekendtesting
 
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-6Marakana Inc.
 
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 6Marakana Inc.
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docxAfrasAhmad3
 
ST LAB 15 (1).docx
ST LAB 15 (1).docxST LAB 15 (1).docx
ST LAB 15 (1).docxAfrasAhmad3
 
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 scriptsSokunthaneth Chhoy
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014Mark Rackley
 
Search driven architecture in SharePoint
Search driven architecture in SharePointSearch driven architecture in SharePoint
Search driven architecture in SharePointJim Lennox
 
CSS Selector in Selenium WebDriver | Edureka
CSS Selector in Selenium WebDriver | EdurekaCSS Selector in Selenium WebDriver | Edureka
CSS Selector in Selenium WebDriver | EdurekaEdureka!
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQueryMark Rackley
 
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 SharePointMark Rackley
 
Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1Session 02 - Object Identification - Part 1
Session 02 - Object Identification - Part 1SiddharthSelenium
 
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 StudioKatalon 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 solutionsQUONTRASOLUTIONS
 
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 jQueryshabab shihan
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!Ana Cidre
 
The SharePoint & jQuery Guide
The SharePoint & jQuery GuideThe SharePoint & jQuery Guide
The SharePoint & jQuery GuideMark Rackley
 
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 - SPTechConSPTechCon
 

Ähnlich wie Locators in selenium - BNT 09 (20)

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
 
Search
SearchSearch
Search
 

Kürzlich hochgeladen

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
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.pdfAdmir Softic
 
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 Delhikauryashika82
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
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.pptxnegromaestrong
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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).pptxVishalSingh1417
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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).pptxVishalSingh1417
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Kürzlich hochgeladen (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.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
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

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

Hinweis der Redaktion

  1. Reference:W3schools.com