SUM
SUM

Reputation: 1661

Selenium convert Xpath (ID and Class) to CSS selector

Trying to understand how to convert this Xpath to CSS locator.

 //div[@id='State']//input[@class='state-dropdown list']

Upvotes: 2

Views: 1905

Answers (4)

optimistic_creeper
optimistic_creeper

Reputation: 2799

Try with:

div#State * > input.state-dropdown.list

For more reference follow the link:

http://www.w3schools.com/css/css_combinators.asp

Upvotes: 0

Saurabh Gaur
Saurabh Gaur

Reputation: 23805

//div[@id='State']//input[@class='state-dropdown list']

The valid cssSelector for this xpath would be :-

div#State input.state-dropdown.list

From CSS Selector Reference

  • CSS #id Selector use to locate an element with their id attribute value

  • CSS element element Selector use to locate element that is inside paranet element. In your case, cssSelector would be locate <input> elements that would be inside <div> element.

  • CSS .class Selector use to locate an element with their class attribute value

Upvotes: 1

Happy Bird
Happy Bird

Reputation: 1142

div#State input.state-dropdown.list

Upvotes: 0

Sudharsan Selvaraj
Sudharsan Selvaraj

Reputation: 4832

the cssSelector for above xpath is

div#State input.state-dropdown.list

here # represents id and . represents class name.

Upvotes: 1

Related Questions