top of page
Search

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.

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.

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.


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.


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.


For Attributes

For Xpath

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


For CSS

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



Recent Posts

See All

Comments


Contact Us

PR World Trade Center, 108, near bus stand, Jalandhar, Punjab 144001

Phone or Whatsapp

+91-7652933997

     

bottom of page