QA Interview Handbook
  • 🏠Home Page
  • About Testing
    • 💖Qualities of A Great Tester
  • Manual Testing
    • 💡Overview
      • ✋Demand for Software Testing
      • 😄Tester's Role in Manual Testing
      • 7️Testing Principles
      • 🚨V & V
      • ❔Interview Questions
    • ♻️SDLC
      • 📒Phase 1: Planning
      • 🔍Phase 2: Requirement Analysis
      • 👔Phase 3: Design
      • ⛑️Phase 4: Development
      • 🧪Phase 5: Testing
      • 🚚Phase 6: Deployment
      • 🖱️Phase 7: Maintenance
      • ⚔️Common Challenges
      • ❔Interview Questions
    • 🌀STLC
    • 🌊Waterfall
    • ✳️Agile
      • 😁Tester's Role in Scrum
    • 🔢Types
      • ⬜White Box Testing
      • ⬛Black Box Testing
        • 🔰Techniques Used in Black Box Testing
        • 🚘Functional Testing
          • 1️⃣Unit Testing
          • 2️⃣Integration Testing
            • 🔰Techniques Used in Integration Testing
          • 3️⃣System Testing
            • 📼Types of System Testing
            • 🌊Phases of System Testing
            • 🌀Regression Testing
            • 🌫️Smoke Testing
          • 4️⃣Acceptance Testing
            • ⚙️User Acceptance Testing
            • 🅰️Alpha Testing
            • 🅱️Beta Testing
        • 🕳️Non Functional Testing
      • 📑Grey Box Testing
    • 🪄User Story
      • ⏺️Sample User Stories
    • 📓Test Cases
      • ⏺️Sample Test Cases
      • ❔Interview Questions
    • ✖️Defect Life Cycle
      • ☣️Priority + Severity
      • ⏺️Sample Defect Reports
      • ❔Interview Questions
      • 🐛Buggy Questions
    • 🌐Atlassian JIRA
      • 🐞JIRA Issues
      • ❔Interview Questions
    • ❔Interview Questions
  • Accessibility Testing
    • 💡Overview
    • 🤓Tester's Role in Accessibility Testing
    • 📚WCAG Principles
      • 👁️Perceivable
      • 🏹Operable
      • 🧠Understandable
      • 🤖Robust
    • 🔧Axe DevTools
      • ❔Interview Questions
    • 📓Test Cases
    • ❔Interview Questions
  • API Testing
    • 💡Overview
    • 😀Tester's Role in API Testing
    • 🍊HTTP Methods & CRUD
      • 🍂HTTP Status Codes
    • 🍍API Tools
      • 🟠Postman
        • ☄️Sending your first API request
        • 🔬HTTP Requests with Java
        • 🎲GitHub Sample
        • ❔Interview Questions
      • ⛑️REST Assured
        • 🎇Dependency
        • ❔Interview Questions
    • 📓Test Cases
    • 🦧API Cheatsheet
    • ❔Interview Questions
  • Database Testing
    • 💡Overview
    • 😆Tester's Role in Database Testing
    • 🔵SQL
      • ⛓️Constraints
      • 🛢️Referencing a Column
      • 🔼DDL Commands
      • 🔼DML Commands
        • 🖌️Operators
        • 🛠️Functions
          • ⏯️Aggregate Functions
        • 🎅Clauses
          • ⏫Join Clauses
          • 🔵Filter Clauses
          • ⏬Set Operations
      • 🃏Wildcard Character
      • ❔Interview Questions
    • 📓Test Cases
    • 🧤SQL Practice Sites
    • 🫐SQL Cheatsheet
    • ❔Interview Questions
  • Java
    • ⛩️Introduction
    • 😄Tester's Reason to Learn Java
    • Ⓜ️Main Method
      • ❔Interview Questions
    • 📐Variables & Types
      • 🪢Special Types
    • 🥁Modifiers
    • 🅾️Operators
    • 🪡String
      • 🩺String Methods
        • String Method Problems
      • 🚨Delimiter
      • ❔Interview Questions
    • 🖇️Conditionals
      • 💎Common If Statements
      • 💎Common Ternary Operator Statements
    • Ⓜ️Math Class
    • 🌊Loops
      • 💎Common Loop Examples
      • 🔃Nested For Loops
    • 🍼OOPS
      • 🏛️Classes and Objects
        • ❔Interview Questions
      • 🎃Constructor
        • ⚡Static
          • ❔Interview Questions
        • 📍This() & Super()
          • ❔Interview Questions
        • 🍀Finalization
      • 🔓Encapsulation
      • 🐥Inheritance
      • 🦋Polymorphism
      • 🕸️Abstraction
    • 🏮Java Practice Sites
    • ☑️Data Structures + Algorithms
      • 🅾️Big O
      • ☑️Data Structures
        • 🔸Array
        • 🔳Array Problems
        • Page
      • 🪟Sliding Window Technique
        • 🪟Sliding Window Problems
        • 🥐LeetCode #53
        • 🥐LeetCode #209
    • ❔Interview Questions
  • Automation Testing
    • 🚰Flow
      • 💡Overview
      • 🤩Tester's Role in Automation Testing
      • 🍀Selenium
        • 🕸️Selenium WebDriver
          • 🕷️WebDriver Commands
            • 🌐WebElement
              • 🔆HTML Tags
              • 🔬Find Element(s)
              • 🦎Locators
                • ❌Xpath
                • 🏰CSS Selector
                • 📀DOM
                • 🏠Quick Reference for XPath + CSS
            • ✋Waits
            • Browser Management
            • 🏎️Navigation
            • Alerts
          • 🏷️Advanced User Interactions
            • 🗯️Action vs. Actions
            • 💧Drop Down
            • ✅Check Box
            • 🖇️Forms
          • ⚠️Exceptions
        • 🍏OOPS + Selenium
        • 🚢Frameworks
          • ⚓Module Based Framework
          • 🎹Keyword Driven Framework
          • 🎋Data Driven Framework
          • 🌺Hybrid Framework
          • 🌴Log4j
          • 📄Page Object Model
        • 🧪Testing Frameworks
          • 💡TestNG
          • 🉑JUnit
          • 🥒BDD
            • 🥒Cucumber
        • 🌉Selenium Grid
          • ✖️Desired Capabilities
        • ❔Interview Questions
      • 🔄API Testing with Selenium
      • ⏪Database Testing with Selenium
      • Ⓜ️Maven
      • 🐙Git
        • ❔Interview Questions
      • 🕵️‍♂️Jenkins
        • ❔Interview Questions
      • 🐳Docker
        • ❔Interview Questions
      • 📙AWS
        • ❔Interview Questions
  • Behavioral
    • 📣Mixed Interview Questions
    • ⭐STAR Method
      • 🌟Sample Responses
Powered by GitBook
On this page
  • What are the different approaches to using XPath and CSS Selector?
  • What are the differences between XPath and CSS locators?
  • Traversal:
  • Performance:
  • Readability:

Was this helpful?

  1. Automation Testing
  2. Flow
  3. Selenium
  4. Selenium WebDriver
  5. WebDriver Commands
  6. WebElement
  7. Locators

Quick Reference for XPath + CSS

What are the different approaches to using XPath and CSS Selector?

Description
XPath
CSS Selector

Whole WebPage

/html

html

Whole WebPage body

/html/body

body

Image element

//img

img

Link

//a[@href = 'url']

a[href = 'url']

Direct Child

//div/a

div > a

Id

//tagName[@id=’idValue’]

tagName#idValue

Class

//tagName[@class=’classValue’]

tagName.Value of Class attribute

Attribute

//tagname[@attribute-name=’value1′]

tagName[attribute=Value of attribute]

Multiple Attributes

//input[@type='submit' and @name='btnLogin']

tagname[attribute1='value1'][attribute2='value2']

Contains

//*[contains(@type,'sub')]

tagname[attribute*=substring]

Starts with

//tagname[starts-with(@attribute, ‘Start value’)]

tagname[attribute^=prefix of the String]

Ends with

//tagname[ends-with(@attribute, ‘End value’)]

tagname[attribute$=suffix of the String]

Matches

//*[matches(@type,'value')]

N/A

First Child

//ul[@id=’list’]/li[1]

ul#list li:first-child

Last Child

//ul[@id=’list’]/li[last()]

ul#list li:last-child

nth Child

//ul[@id=’list’]/li[3]

ul#list li:nth-child(3)

Text Value

//td[text()=‘textname']

N/A

Element preceding some sibling

E2/preceding-sibling::E1

N/A

Sibling element immediately preceding

E/preceding-sibling::*[1]

N/A

User interface element that is disabled

E[@disabled]

E:disabled

Checkbox (or radio button) that is checked

//*[@checked]

*:checked

Text Value

//td[text()=‘textname']

N/A

What are the differences between XPath and CSS locators?

Traversal:

❎ XPath allows bidirectional traversal.

//div[@id='id']//preceding::input
//div[@id='id']//following::input

➡️ CSS only moves forward.

 div#id ~ input

👉 So XPath has more powerful traversal.

Performance:

✅ CSS selectors are faster since browsers optimize CSS.

Readability:

✅ CSS locators are more concise and readable.

input[type='text']
//input[@type='text']
PreviousDOMNextWaits

Last updated 1 year ago

Was this helpful?

🚰
🍀
🕸️
🕷️
🌐
🦎
🏠