简体   繁体   中英

C# Selenium QA - how to extract the value of custom attribute

I have complex DOM structure with dynamically changing values of the HTML id attributes. Selenium is returning "null" when I attempt to extract the values of the "custom" attributes.

I need to extract the value of parentId (namely I need the "qqq-bbb", which is different on every reload)

 //Selenium(C#): // evaluates to "null" string someStringName = someIWebElement.GetAttribute("parentId"); //HTML tag (example): // in Chrome the parentId is visible and unique <g id="333-aaa" parentId="qqq-bbb"> 

Solution: (based on recommendation in comment#2). Issuing the following command returns as string the contents of the tag AND by applying the right parse you get the attribute value you need

 string outerHTML = foundIWebElement.GetAttribute("outerHTML"); 

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