Friday 14 February 2014

How to identify the elements using cssSelector in selenium Webdriver?

In this article I am going to explain you how we can use cssSelectors to identify the web elements using selenium web driver.

What is CssSelector in selenium web driver?

cssSelector is used to find the specific element in the given webpage.
Some of the below examples will demonstrate how we can write the cssSelector expressions.

Find all elements with tag input
input
Find all input tag element having  attribute type = ‘hidden’
input[type='hidden']
Find all input tag element having  attribute type = ‘hidden’  and name attribute = ‘ren’
input[type='hidden'][name='ren']
Find all input tag element with attribute type containing ‘hid’
input[type*='hid']
Find all input tag element with attribute type starting with ‘hid’
input[type^='hid']
Find all input tag element with attribute type ending with ‘den’
input[type$='den']

You can find the element containing specific text using below CSS Selector syntax.
$("h3:contains('Cloud')")

Above css will select the element H3 containing text Cloud


What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books

Contributors