­

Subscribe

About Me

My photo
Welcome to my corner of the internet! I’m a software engineer by day, mechanical engineer by degree, some-time traveler, music lover, and self-proclaimed motivational speaker by... well, any spare minute I can find. When I’m not busy debugging code, you can find me lost in a new place, jamming to a mix of Indian and Western music (yes, I’m the one who creates playlists that make no sense), or pondering the mysteries of the universe, from physics to geopolitics. Oh, and if you need some motivation or a good laugh, I’m your go-to person—I'm basically a walking TED talk. Stick around for random musings, technical rants, and possibly some okayish poetry ✍️!

Translate

Wednesday, February 12, 2025

Selenium Webdriver (Part 1) - Locators

Locators


  1. CSS Selectors
    1. attribute      -- tagName[attribute='value']
    2. className  -- tagName.className
    3. Id                -- tagName#Id
    4. parent to child traverse -- parentTagName childTagName
    5. nth child     -- tagName[attribute='value']:nth-child(index) 
    6. Regex Eg    -- "input[type*='pass']"
    7. Notes -
      1. child to parent traverse is not possible in CSS
      2. tagName.className --> here tagName is optional, we can write .className also but the className should be unique.
      3. class="submit signInBtn" --> here are 2 identifiers, we can choose any one of them.
  2. XPath
    1. attribute      -- //tagName[@attribute='value']
    2. parent to child traverse -- //parentTagName/childTagName
    3. index           -- //tagName[@attribute='value'][index]
    4. Regex Eg    -- //button[contains(@class,'submit')]
    5. parent to child to child traverse Eg -- //header/div/button[1]/following-sibling::button[1]
    6. parent to child to parent to grandParent to child traverse Eg -- //header/div/button[1]/parent::div/parent::header/a
    7. Notes - 
      1. customized Xpath - both the words in the class name must be used. Eg: //button[@class='submit signInBtn']
  3. ID, name, className 
    1. just the ID/name/className respectively.
  4. With text
    1. linktext
    2. normalized-space()='xyz'
    3. xpath Eg- //button[text()='Log Out']

No comments:

Post a Comment

Persistent Automation Testing Interview Questions (5+ YOE)

What is Serialization and Deserialization and how to perform it? WAP for changing d to D in "I am from India" WAP for counting no....