Convert Xpath to CSS selector

12,480

Solution 1

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

Solution 2

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
Share:
12,480

Related videos on Youtube

Samoht Rusconi
Author by

Samoht Rusconi

Updated on June 04, 2022

Comments

  • Samoht Rusconi
    Samoht Rusconi almost 2 years

    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?

    • Tamil Selvan C
      Tamil Selvan C over 5 years
      try #giftcard-form div:nth-child(3) button
    • connexo
      connexo over 5 years
      cssify.appspot.com form#giftcard-form > div:nth-of-type(3) > div > button
    • Alok
      Alok over 5 years
      Welcome to SO. go through the guidelines on how to ask a good question.Help Center and how to ask question. Regarding your question paste the html snippet of the webelement that you want.
    • Samoht Rusconi
      Samoht Rusconi over 5 years
      @Alok Thank you for your answer.
  • Mark Mayo
    Mark Mayo almost 3 years
    any substitute? cssify isn't working any more :/
  • New Guy
    New Guy over 2 years
    @MarkMayo, I might be late but check again. It's working.
  • Mark Mayo
    Mark Mayo over 2 years
    yep, seems back!