Search code examples
rubyxpathautomated-testscucumbercapybara

Map element not using xpath


I am using site-prism and I am having difficulties in this situation, I don't want to use xpath.

Ele esta implementado desta maneira: <img class="profile-pic" src="https://quasar-flash-staging.herokuapp.com/assets/1-1987dadded3f7a94e2433de1d56bf0a728a2f1ae719d246a175c701f3622ea74.jpg">

I was only successful when I used the xpath below.

element :btn_fechar, :xpath, '//*[@id="main-wrapper"]/header/nav/div[2]/ul[2]/li/a/img'


Solution

  • It's impossible to say for sure what CSS selector would work for you here without more of the HTML structure to ensure whatever is specified doesn't match multiple things. Guesses would be things like

    element :btn_fechar, :css, 'img.profile-pic'
    element :btn_fechar, :css, '#main-wrapper img.profile-pic'
    element :btn_fechar, :css, '#main-wrapper header img.profile-pic'
    

    although judging by the name you're using for your element you probably actually want to find the a element which would actually be the "button" -- You don't provide enough info here to determine how to identify that element but assuming you have followed reasonable practices and have a title attribute on the a element you could do something like

    element :btn_fechar, :link, 'title attribute value'