Search
  • 9to5 Technologies

Some shortcuts to find elements by CSS in Selenium Webdriver.


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’]”).


#besttestingtools #besttoolsforsoftwaretesting

#besttestingtools #besttoolsforsoftwaretesting #istqbcertificationtraininginchandigarh #jmetertraininginchandigarh #Loadrunnertraininginchandigarh #qatools #qtptraininginchandigarh #seleniumtraininginchandigarh #TestingTools #testingtraininginchandigarh

1 view

 Address.212, 2nd Floor, Grand Mall, Jalandhar, Punjab 144001, India

Tel. +91-7710795555

      +91-7710793555

QUICK LINKS

© 2019 by NTF. Proudly created with 9to5Technologies  privacy policy