Selenium - ASP.NET generated IDs (JQuery like selection)
JQuery supports a syntax of $("span[id$='Label1']")
to allow selec开发者_StackOverflowtion of ASP.NET INamingContainer generated ID's that have been prefixed with "ct100$...".
We are using Selenium and are looking for a similar way to select elements, ignoring the prefixes that ASP.NET generates.
Ideas?
Use:
//span[@id[substring(.,string-length()-5)='Label1']]
In theory you can do it using XPath selectors like this:
//div[ends-with(text(), 'MyControlId')]
but I have a feeling that you can't use the ends-with
function with Selenium as it's not part of XPath 1.0. You might need something more ugly like this:
//div[substring(text(), string-length(text()), 11)='MyControlId']
If the project is in .Net 4 its now possible to have static naming of dynamic controls.
Read here http://www.dotnetcurry.com/ShowArticle.aspx?ID=492
Makes life a bit easier if you have the luxury to have it done this way. Otherwise a proper formed XPath will work (But is deadly slow test IE)
Cheers, Stefan
精彩评论