What are CSS Selectors and how they can be used as locators in Selenium Webdriver?

0 votes
May 24, 2019 in Selenium by Randeep
229 views

1 answer to this question.

0 votes

Hi Randeep, CSS Selectors are string patterns used to identify an element based on a combination of HTML tag, id, class, and attributes. Locating by CSS Selector is more complicated than locating by Id or Name, but it is the most common locating strategy of advanced Selenium users because it can access even those elements that have no ID or name. CSS Selectors have many formats, but we will only focus on the most common ones.

  • Tag and ID: Syntax for CSS Selector with Tag and ID is css=tag#id
    For eg. "css=input#email"

  • Tag and class: Syntax for CSS Selector with Tag and ID is css=tag.class
    For Eg. "css=input.inputtext"

  • Tag and attribute: Syntax for CSS Selector with Tag and ID is css=tag[attribute=value]
    For eg. "css=input[name=lastName]"

  • Tag, class, and attribute: Syntax for CSS Selector with Tag and ID is css=tag.class[attribute=value]
    For eg. "css=input.inputtext[tabindex=1]

  • Inner text: Syntax for CSS Selector with Tag and ID is css=tag:contains("inner text")
    For eg. "css=font:contains("Boston")"

answered May 24, 2019 by Pratibha

Related Questions In Selenium

0 votes
1 answer

How can Custom Firefox Profiles be created and used in Selenium?

Hi Vijay, to create Custom Firefox Profile ...READ MORE

answered May 24, 2019 in Selenium by Abha
• 27,930 points
175 views
0 votes
1 answer

How ID and Class can be used as a CSS Selector?

Hey Bruce, to identify a web element ...READ MORE

answered Jun 21, 2019 in Selenium by Abha
• 27,930 points
101 views
0 votes
1 answer
0 votes
1 answer

What is Marionette driver and how it can be used to instantiate Firefox webdriver?

Hey Manju, Marionette driver is the new driver ...READ MORE

answered Jul 15, 2019 in Selenium by Anvi
• 14,090 points
623 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
3,129 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,362 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,890 points
2,508 views
0 votes
1 answer

Which methods which can be used to handle pop-up and alerts in Python Selenium Webdriver?

Hey Kishor, Python Selenium webdriver provides following ...READ MORE

answered Jul 29, 2019 in Selenium by Abha
• 27,930 points
81 views
0 votes
1 answer

Can anyone explain how an AJAX call can be handled in Selenium webdriver?

Hello Megha, to demonstrate how AJAX calls are ...READ MORE

answered May 8, 2019 in Selenium by Pratibha
• 3,690 points
312 views