简体   繁体   中英

How use selenium to click on button which name is generated by 6 digits?

How can i click on button which pattern name in is中模式名称的按钮

[u<6digits>_3] //?
Example:
 u123456_3 
Does selenium support any member with that ability? You can see it while logging to facebook.

If the id is automatically generated you shouldn't use it for selenium, since you cannot assume it will be always the same (maybe the next time they restart a server or if you get a different server from a load balancer the generated id is different)

Try to use another attribute of the element, like class or name, using XPath you can usually define a way to identify an element without having to use the id.

In this link you can check how it works.

For regular expressions, I would use Javascript injection and getElementByTagName to get the buttons. From there, iterate of them matching their ID against the regex, and return the matching ID to selenium for you to use.

However, if you can get away with not using regular expressions, CSS supports starts with and ends with properties, and a locator like css=button[id^="u"][id$="_3"] may work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM