return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - How to get an element that has a dynamic selector in Cypress - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get an element that has a dynamic selector in Cypress - Stack Overflow

programmeradmin1浏览0评论

My script has a button which leads to an external site where I need to input some information in a field.

I'm not able to find a way to select that field because it's within an iframe and also has a dynamically generated ID. That ID has 2 characters at the end that are always consistent.

So far I've tried:

cy.get('#*_2'); --> Trying to use a wildcard to click on the element that has a _2 at the end but it does not work

I've tried using a cy.get('input[data-collect-as="input"]') --> It's not able to find this element either.

Any help would be appreciated.

My script has a button which leads to an external site where I need to input some information in a field.

I'm not able to find a way to select that field because it's within an iframe and also has a dynamically generated ID. That ID has 2 characters at the end that are always consistent.

So far I've tried:

cy.get('#*_2'); --> Trying to use a wildcard to click on the element that has a _2 at the end but it does not work

I've tried using a cy.get('input[data-collect-as="input"]') --> It's not able to find this element either.

Any help would be appreciated.

Share Improve this question asked Jun 4, 2021 at 18:56 qatester123qatester123 1432 gold badges3 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

The shorthand id selector #myid can only be used with the exact value, but id is still an attribute so you can use an attribute selector with a wildcard

cy.get('[id$="_2"]')         // $= means value ending with 

There's a bunch variations, see Selectors - Attribute


The other approach you tried should work like this

cy.get('div[data-collect-as="input"] input') 

This gets a child input with ancestor div[data-collect-as="input"] - the space denoting two separate elements and the relationship is ancestor -> descendant.

You can add more precision

cy.get('div[data-collect-as="input"] > div.wrp > input') 

where the > indicates a parent-child relationship.

You can use the pattern attribute value as well.

cy.get('input[pattern="[0=9]*"]')
发布评论

评论列表(0)

  1. 暂无评论