admin管理员组

文章数量:1414614

I want to know that is possible to find element by partial id, because on page which I'm testing id is dynamic(The first part of the id has a variable number) and I can't know whole id.

I want to know that is possible to find element by partial id, because on page which I'm testing id is dynamic(The first part of the id has a variable number) and I can't know whole id.

Share Improve this question edited Jun 23, 2015 at 12:10 alecxe 475k127 gold badges1.1k silver badges1.2k bronze badges asked Jun 23, 2015 at 12:03 tealangtealang 2011 gold badge3 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

There are multiple ways to do it, e.g. with 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 an XPath (no ends-with here):

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

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

本文标签: javascriptProtractor id of element dynamically generatedStack Overflow