-->

C# Selenium QA - how to extract the value of custo

2020-08-01 08:41发布

问题:

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"> 

   

回答1:

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");