top of page
Search

Some shortcuts to find elements by CSS in Selenium Webdriver.

  • qatestingthreesixt
  • Dec 1, 2021
  • 1 min read

There are Some shortcuts to find elements by CSS in Selenium Webdriver.

  1. You can use # in place of id, the syntax would be $$(“input#txtLogin”).

2. You can use dot(.) in place of class, the syntax would be $$(“input.txt_box”).


3. To search all the classes having value txt_box, you can use $$(“.txt_box”).


4. You can also search an element by using multiple attributes like $x(“//input[@id=’txtLogin’ and @class=’txt_box’]”).


There are some other functions to recognise an element with CSS as follows:

nth of type

  • To find all element with “input” tag under div anywhere in the page we use $x(“//div/input”)


  • If you want to find first input tag using xpath then we use index=1 as $x(“//div/input[1]”)


  • For CSS, you can use $$(“div input:nth-of-type(1))”):


Prefix Match(^=)

If you want to find all elements having id starting with “txt”, please use $$(“input[id^=’txt’]”).


Suffix Match($=)

If you want to find all elements having id ends with “Login”, please use $$(“input[id$=’Login’]”)


Substring (*)

If you want to find all elements having id contains string “txt”, please use $$(“input[id*=’txt’]”).


 
 
 

Recent Posts

See All

Comentários


Contact Us

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

Phone or Whatsapp

+91-7652933997

     

bottom of page