How do we locate both Data QA Id and CSS Class using Selenium C# ?

We're trying to locate both a DataQAid attribute and also see if its class ng-invalid, (Angular Material Textbox Error)

This is what wrote so far:

private By PhoneError => By.XPath("//*[@attr.data-qa='homephone']");

enter image description here

Resource: https://stackoverflow.com/questions/24120263/find-element-in-selenium-using-xpath-or-css-selector

  • is your locator working ? why are using @attr.data-qa instead of @data-qa
    – PDHide
    Commented Aug 13, 2020 at 8:37
  • 1
    Why do you use 'homephone' when the value is 'homephone-update' ? Commented Aug 13, 2020 at 10:01
  • @NielsvanReijmersdal are you aware of attr.data-qa ? Is it something new or even that is wrong . I never seen such a usage .
    – PDHide
    Commented Aug 13, 2020 at 10:13
  • 1
    @PDHide No, I think it is a miss interpretation of examples Commented Aug 13, 2020 at 17:30

1 Answer 1

By.XPath("//*[@data-qa='homephone-update' and @class='ng-invalid']");

Try this

  • This answers the how to use both attr and class. I do not think it solves the issue of the OP, as the data-qa field is homephone-update. Commented Aug 13, 2020 at 10:01
  • @NielsvanReijmersdal thanks Niel i updated it , i didnt notice the remainingg
    – PDHide
    Commented Aug 13, 2020 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.