HomeSelenium

Selenium Locators – Using last-child in CSS Selectors

Selenium Locators – Using last-child in CSS Selectors

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

In the previous article, I have practically demonstrated the usage of the first-child in CSS Selectors.

In this article, I am going to practically demonstrate using the last-child in CSS Selectors.

Let’s get started.

Selenium Locators – Using last-child in CSS Selectors

Follow the below steps to practice using last-child in CSS Selectors:

1) Open http://compendiumdev.co.uk/selenium/basic_web_page.html in Chrome Browser, where ChroPath is already installed (Refer ChroPath installation in Chrome Browser here and usage in Chrome Browser here ) as shown below:

I have taken a very basic Web Application for demonstration as shown in the below screenshot to make your learning easy:

Absolute XPath - Opening Basic Application

2) Open ‘ChroPath’ functionality as shown below in the Chrome Browser:

Absolute XPath - Open ChroPath

3) Select ‘CSS Sel..’ option from the ‘Selectors’ dropdown as shown below:

Relative CSS Selectors - CSS Sel

4) Expand all the tags on the left side (i.e. <head> and <body> tags) as shown below:

Relative CSS Selectors - expand tags

5) Let’s locate the last child under the body tag using last-child in the CSS Selectors as shown below:

body > *:last-child

Note: * symbol in the above CSS Selector stands for any tag

Let’s execute the above Relative CSS Selector in the ChroPath and observe that the last child tag under the body tag got located as shown below:

CSS Selectors - last-child body

6) Let’s locate the last child under the head tag using last-child in the CSS Selectors as shown below:

head > *:last-child

Note: * symbol in the above CSS Selector stands for any tag

Let’s execute the above Relative CSS Selector in the ChroPath and observe that the last child tag under the head tag got located as shown below:

CSS Selectors - last-child head

7) Let’s locate the last child under the html tag using last-child in the CSS Selectors as shown below:

html > *:last-child

Note: * symbol in the above CSS Selector stands for any tag

Let’s execute the above Relative CSS Selector in the ChroPath and observe that the last child tag under the html tag got located as shown below:

CSS Selectors - last-child html

8) Let’s locate the last tag using last-child in the CSS Selectors as shown below:

p:last-child

Let’s execute the above Relative CSS Selector in the ChroPath and observe that the last tag got located as shown below:

CSS Selectors - last-child p

9) Let’s locate the last tag having the id as para2 using last-child in the CSS Selectors as shown below:

p[id=’para2′]:last-child

Let’s execute the above Relative CSS Selector in the ChroPath and observe that the last tag having the id attribute value as para2 got located as shown below:

CSS Selectors - last-child p id

Here concludes the usage of last-child in CSS Selector.

In the next article, I will practically demonstrate the usage of last-child in CSS Selector.

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 *