How to use css selector in selenium using Java

0 votes
I am new to selenium and want to know as how we find elements using ID Locator there is CSS Locator also how can I use that to locate an element?
Dec 21, 2018 in Selenium by Jino
• 5,810 points
1,018 views

1 answer to this question.

0 votes

Hello @Jino,

CSS Selector is pretty easy to use. Here is a detailed way of using the ID locator (CSS Selector).

Here's an example where we would access the “Email” text box present in the login form at Gmail.com.

The Email textbox has an ID attribute whose value is defined as “Email”. Thus ID attribute and its value are often wont to create CSS Selector to access the e-mail textbox.

Creating CSS Selector for web element

Step 1: Locate/inspect the web element (“Email” textbox in our case) and notice that the HTML tag is “input” and the value of the ID attribute is “Email” and both of them collectively make a regard to the “Email Textbox”. Hence the above data would be wont to create CSS Selector.

Verify the locator value

Step 1: Type “css=input#Email” i.e. the locator value within the target box up the Selenium IDE and click on on the Find button. Notice that the e-mail Text box would be highlighted.​

Syntax

css=<HTML tag><#><Value of ID attribute>

  • HTML tag – it's the tag which is employed to denote the online element which we would like to access.
  • # – The hash sign is used to symbolize ID attribute. It is mandatory to use hash sign if ID attribute is getting used to make CSS Selector.
  • Value of ID attribute – it's the worth of an ID attribute which is being accessed.
  • The value of ID is usually preceded by a hash sign.

Hope this helps.

answered Dec 21, 2018 by Nabarupa

Related Questions In Selenium

+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
7,952 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,488 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,500 points
10,236 views
0 votes
1 answer

How to wait for the webpage to load in selenium using java

Firstly, when you launch a web application, ...READ MORE

answered Aug 29, 2018 in Selenium by bug_seeker
• 15,520 points
1,693 views
0 votes
2 answers

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,500 points
12,712 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
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,910 points
6,680 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
+10 votes
17 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
194,141 views
+3 votes
1 answer

How to use wait in selenium java?

There are different types of wait you ...READ MORE

answered Dec 18, 2018 in Selenium by Nabarupa
548 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP