Samoht Rusconi
Samoht Rusconi

Reputation: 75

Convert Xpath to CSS selector

I am struggling in converting the follow Xpath to CSS: "//form[@id=\'giftcard-form\']/div[3]/div/button". I know I could use the Xpath for my selenium JS but it doesn't work in my case for some odd reason. I was successful in converting an easier one and using its in the script but I can't get this one right. Anyone can help?

Upvotes: 3

Views: 17934

Answers (2)

New Guy
New Guy

Reputation: 393

One should learn how to write css selectors, but a for a quick fix, try: cssify

For example, I put in your xpath and it spit out: form#giftcard-form > div:nth-of-type(3) > div > button

Btw, you had an error in your xpath, it should be this: //form[@id='giftcard-form']/div[3]/div/button

Upvotes: 6

undetected Selenium
undetected Selenium

Reputation: 193388

For XPath as:

//form[@id=\'giftcard-form\']/div[3]/div/button

The equivalent CSS would be:

form#giftcard-form>div:nth-of-type(3)>div>button

Upvotes: 2

Related Questions