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,670 points
262 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

0 votes
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,510 points
4,004 views
0 votes
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,510 points
12,673 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 5, 2018 in Selenium by nsv999
• 5,510 points
7,131 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 28, 2018 in Selenium by bug_seeker
• 15,400 points
525 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,163 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,375 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,527 views
+9 votes
15 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
114,134 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
119 views