简体   繁体   中英

How to Define Element By Two Attributes C#?

Is it possible to define an element of a web page by two attributes? For instance, I can find the element by its innertext

Element imagePage = ActiveBrowser.Find.ByContent(pageNumbers[p],FindContentType.InnerText);

Or I can define an element by part of its element id

Element imagePage = ActiveBrowser.Find.ById("p:p") 

But can I define it by using both? The elements themselves are recreated every time the program is run so the only constant is the inner text but that is not enough to differentiate it from other elements on the web page, the only way I can think to differentiate the element is by adding another identification method which will use the first part of the element id, in this case p , that also remains constant and is unique to that specific element. Any help will be greatly appreciated.

If you're talking in context of Telerik's UI testing framework, then look into Find.AllByExpression()

// Create an HTMLFindExpression element
HTMLFindExpression expr = new HTMLFindExpression("id=?sam","class=~bar","textcontent=!foo");

// Return all elements matching HTMLFindExpression
IList<Element> allSams = Find.AllByExpression(expr);

More here: http://docs.telerik.com/teststudio/user-guide/write-tests-in-code/intermediate-topics/element-identification/finding-page-elements.aspx

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