Element protractor id is dynamically generated

I want to know that it is possible to find an element by a private id, because in the page I am testing the id is dynamic (the first part of the id has a variable number) and I cannot know the entire id.

+3


source to share


1 answer


There are several ways to do this, for example. using a CSS selector:

// starts-with
element(by.css("div[id^=test]"));

// ends-with
element(by.css("div[id$=test]"));

// contains
element(by.css("div[id*=test]"));

      



Or, with XPath (endlessly here):

// starts-with
element(by.xpath("//div[starts-with(@id, 'test')]"));

// contains
element(by.xpath("//div[contains(@id, 'test')]"));

      

+5


source







All Articles