HomeSelenium

Locators for Selenium – Demonstrating CSS Selector Locator

Locators for Selenium – Demonstrating CSS Selector Locator

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

In the previous articles, I have explained what are locators? and Different types of locators.

In this article, I am going to practically demonstrate the usage of CSS Selector locators for locating the UI elements on the Web Pages.

Note: This article is just for demonstrating CSS Selectors at a high level. CSS Selectors will be explained in detail in the upcoming articles.

Let’s get started.

Locators for Selenium – Demonstrating CSS Selector Locator

Follow the below steps for locating the UI elements on the Web Pages using CSS Selector Locator:

1) Install Selenium IDE, if not installed in your chrome browser (Refer steps to install Selenium IDE in your chrome browser)

2) Navigate to http://omayo.blogspot.com/ in your chrome browser as shown below:

Locators for Selenium - Navigate to Omayo in Chrome

3) Right click on the ‘ClickToGetAlert’ button and select ‘Inspect’ option as shown below:

XPath Expressions Locators - Inspect

4) Observe that the HTML code related to the ‘ClickToGetAlert’ button got highlighted as shown below:

XPath Expressions Locators - Code

5) Right click on the above-highlighted HTML line and select ‘Copy’ > ‘Copy selector’ option as shown below:

CSS Selectors Locators - Copy

6) Launch Selenium IDE from Chrome Browser by following the steps provided in below article:

7) Enter any Selenium IDE command say ‘Click’ into the ‘Command’ Text box field as shown below:

Note: Without entering this command ‘Find target in Page’ magnifier icon option will be in a disabled state by default and will be enabled only after entering any command into the ‘Command’ text box field as shown below:

Locate using Link Text - Command

8) Now, type css= into the Target text box field as shown below:

Locators for Selenium - CSS Equals

9) Paste the CSS Selector copied earlier (i.e. in Step 5) into the ‘Target’ Text box field and click on ‘Find target in Page’ search icon option as shown below:

Locators for Selenium - Locator

10) Observe that the ‘ClickToGetAlert’ button on the Web Page got highlighted for a second on clicking the ‘Find target in Page’ option in the above step using the css=#alert1 locator provided in the Target field as shown below:

Locators for Selenium - Located

As the ‘ClickToGetAlert’ button got highlighted using the CSS Selector locator (i.e. css=#alert1) provided in Selenium IDE, we can confirm that the give CSS Selector locator is able to locate the ‘ClickToGetAlert’ using its HTML code’s CSS Selector.

Hence in this example, we have used the CSS Selector locator (i.e. css=#alert1) for locating the ‘ClickToGetAlert’ button on the Web Page.

In the next article, I will demonstrate the next locator i.e. XPath Expression locator for locating the UI elements on the Web Page.

Next Steps:

  • > To learn more about Selenium, continue to the next post (Click on Next Post link below)
  • > Check complete Selenium Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning 🙂

About Me > Arun Motoori

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *