最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Protractor id of element dynamically generated - Stack Overflow

programmeradmin1浏览0评论

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')]"));
发布评论

评论列表(0)

  1. 暂无评论