0

I don't want to use xpath on the elements below.

element :img_login, :xpath, '//[@id="main-wrapper"]/div/section/div/div[2]/div/div/div[1]/img' element :msg_login_senha_invalidos, :xpath, '//[@id="main-wrapper"]/div/section/div/div[2]/div/div/div[2]/div/p'

They are on the page as follows: element img_login

<div class="sc-jRQAMF eRnhep">
<img src="https://quasar-flash-staging.herokuapp.com/assets/login/flashLogo-3a77796fc2a3316fe0945c6faf248b57a2545077fac44301de3ec3d8c30eba3f.png" alt="Quasar Flash">
</div>

element msg_login_senha_invalidos
<p class="MuiFormHelperText-root MuiFormHelperText-contained Mui-error MuiFormHelperText-filled">Login e/ou senha inválidos</p>
stasilvio
  • 17
  • 3

1 Answers1

0

You have asked multiple questions about converting from using XPath to some other type of selector when using Site-Prism. StackOverflow is meant to be a place to come, learn, and improve your skills - not just to get someone else to do your work. It really seems you'd be better off reading up on CSS and how it can be used to select elements. Also note that there's nothing specifically wrong with using XPath, per se, it's just the way people new to testing and selecting elements on a page tend to use it (just copying a fully specified selector from their browser) that leads to having selectors that are way too specific and therefore brittle. A good site for you to learn about the different general CSS selector options available is https://flukeout.github.io/ - and you can look at the built-in selector types provided by Capybara at https://github.com/teamcapybara/capybara/blob/master/lib/capybara/selector.rb#L18

In your current case the below may work, but with the HTML you have provided all that's possible to say is that they will match the elements shown however they may also match other elements which will give you ambiguous element errors.

element :img_login, :css, 'img[alt="Quasar Flash"]' # CSS attribute selector
element :msg_login_senha_invalidos, :css, 'p.Mui-error', text: 'Login e/ou senha inválidos' # CSS class selector combined with Capybara text filter
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Reading your comments more carefully, I realize you've said some unnecessary things. first of all i don't want anyone to do things for me. Secondly, I'm still learning!!... I think it's cool that you solved it, but when you have any comments in this way, send me in private, avoid discovering people before others... thank you very much – stasilvio Jun 04 '21 at 20:17
  • @stasilvio You have asked 2 questions currently visible, that are asking basically the same thing (the elements are slightly different, but the approach - convert XPath to CSS is identical) - Another user with the same or very similar account name has asked a few almost identical questions over the last few months, and then either deleted the questions or their account. I'm sorry if you weren't looking for others to do your work, but by asking the same basic question multiple times that is the appearance – Thomas Walpole Jun 04 '21 at 20:24
  • ok, let's forget about this. Thank you so much for your help. – stasilvio Jun 04 '21 at 21:48
  • do you to automate software testing? – stasilvio Jun 08 '21 at 14:43