lefthandedgoat / canopy

f# web automation and testing library, built on top of Selenium (friendly to c# also)
http://lefthandedgoat.github.io/canopy/
MIT License
507 stars 115 forks source link

Find id without exact id #421

Closed rodsantest1 closed 6 years ago

rodsantest1 commented 6 years ago

Is there a way to find an id if you only know the id ends with certain text?

lefthandedgoat commented 6 years ago

Yes!

#some_id is shorthand for [id='some_id']

There are all kinds of fuzzy matching you can do on css selectors. See the full list here:

https://oscarotero.com/jquery/

For your example you want to do something like "[id $= 'field1']"

You can use that selector on this page and see that it returns the field with id testfield1

http://lefthandedgoat.github.io/canopy/testpages/

Hope this helps!

rodsantest1 commented 6 years ago

Thank you!

amirrajan commented 6 years ago

@rodsantest1 generally speaking: if there is a css selector for it, then it can be done. So I tend to google: "css selector id ends with" and use that stringing within Canopy to see if it works.