Protractor - How to locate element by custom (non HTML) attributes?

前端 未结 2 1515
太阳男子
太阳男子 2021-02-05 15:44

I am using Selenium WebDriver and Protractor to run e2e tests on my angular project. Let\'s say I have an element like:

相关标签:
2条回答
  • 2021-02-05 16:18

    try using:

    element(by.css('[my-unique-id="abc123"]'))
    

    it's easier and more readable than xpath for simple cases.

    more about xpath syntax and when it is usefull: http://www.w3schools.com/xml/xml_xpath.asp

    0 讨论(0)
  • 2021-02-05 16:21

    Try to use xpath:

    element(by.xpath('//div[@my-unique-id="abc123"]'))
    

    or only by attribute

    element(by.xpath('//div[@my-unique-id]'))
    
    0 讨论(0)
提交回复
热议问题