automated-testscapybarasite-prism

I don't want to use Xpath to map the Label element


I don't want to use xpath to map these elements, as we can see the class is the same for everyone. How to do please?

<label class="sc-fzowVh juqfMo">CNPJ:*</label>
<label class="sc-fzowVh juqfMo">CPF: (do usuário)*</label>

xpath:

//*[@id="boxCadastro"]/div/div[2]/div[1]/div/label
//*[@id="boxCadastro"]/div/div[2]/div[2]/div/label

See the image please: enter image description here


Solution

  • Without seeing the HTML surrounding each of those label elements in order to be able to use scoping, the only option is to go with text matching on the label contents

    element :label1, :css, 'label', text: 'CNPJ:*'
    element :label2, :css, 'label', text: 'CPF: (do usuário)*'
    

    or using the :label selector type

    element :label1, :label, 'CNPJ:*'
    element :label2, :label, 'CPF: (do usuário)*'
    

    although having label elements without for attributes is generally a bad practice and negatively affects page accessibility, so you may want to talk to your developers about improving their HTML