top of page

CSS selector in Selenium Webdriver

  • qatestingthreesixt
  • Dec 1, 2021
  • 1 min read

  1. Open Chrome Browser.

  2. Press F12.

  3. Press “ESC”. it will open “Console”. In Console, we can validate our CSS or Xpath whether it is valid or not.

  4. We use some syntax to validate various CSS. Let’s explain.

Direct child

For Xpath

Right click on the element you want to inspect and select “inspect element”. It will highlight the code. In Console, write $x(“//input[@id=’txtLogin’]”) and press Enter. It will search for the direct child element.

ree

If you want find all direct child elements of tag “input” under the type “div”, the syntax is $x(“//div/input”), it will inspect all elements of type “Input” under div.

ree

For CSS

If you want find all direct child elements of tag “input” under the type “div”, the syntax is $$(“div>input”), it will inspect all elements of tag “Input” under div.

ree

Anywhere in the page

For Xpath

If you want find all direct child elements of type “input” under the tag “div” anywhere in the page, the syntax is $x(“//div/input”), it will inspect all elements of type “Input” under div.

ree

For CSS

If you want find all direct child elements of type “input” under the tag “div”anywhere in the page , the syntax is $$(“div input”), it will inspect all elements of tag “Input” under div.

ree

For Attributes

For Xpath

If you want find specific elements of type “input” with id, the syntax is $x(“//input[@id=’txtLogin'”])

ree

For CSS

If you want find specific elements of type “input” with id, the syntax is $$(“input[id=’txtLogin’]”)

ree


Recent Posts

See All

Comments


Contact Us

SCO 171, Chotti Baradari 2, Opposit Pims Hospital  Jalandhar, Punjab 144006

Phone or Whatsapp

 +91-8427053373

     

bottom of page