Thursday, 6 November 2014

CSS Selector examples in selenium webdriver


Below table shows commonly used css Selectors in Selenium.


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']

Below example demonstrates how we can use cssSelectors to identify the elements in Java.
To identify the edit box with name attribute as q, we can use below css expression.
input[name='q']
Above css Selector expression will identify the element with tagname as input and of which name attribute’s value is name.


//find element having name attribute as q using css
           driver.findElement(By.cssSelector("input[name='q']")).sendKeys("css");

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