Using C# and Selenium webdriver for chrome, I trying to get
Each Property, Setting and Config which is in Property tag.
Their sub-item which is in sub-item.
Their value which is in value.
i. No delimiter is used, thus I cant split text if any value has space in between. ii. Property, Setting, and Config are fixed; bu number of sub-item and their values are not fixed. So their positions keep on changing.
What approach should I take?
A sample HTML is given below.
<span class="list_props">
<div style="height:8px;overflow:hidden;clear:left;"></div>
<strong>Profile</strong>
<strong style="font-style:italic;">Prop1:</strong>
<a href="" title="P1-Profile Item 1">P1 Profile Item 1</a>
<strong style="font-style:italic;">Prop2:</strong>
<a href="" title="P2-Profile Item 1">P2 Profile Item 1</a>
<strong style="font-style:italic;">Prop3:</strong>
<a href="" title="P3-Profile Item 1">P3 Profile Item 1</a>
<a href="" title="P3-Profile Item 2">P3 Profile Item 2</a>
<div style="height:8px;overflow:hidden;clear:left;"></div>
<strong>Settings</strong>
<strong style="font-style:italic;">Setting1:</strong>
<a href="" title="Setting1 Value1">Setting1 Value1</a>
<div style="height:8px;overflow:hidden;clear:left;"></div>
<strong>Config</strong>
<strong style="font-style:italic;">Config:</strong>
<a href="" title="config-1">config 1</a>
<a href="" title="config-2">config 2</a>
</span>
I've tried a few things, but best I could reach is given below. Its not giving proper result.
var props = c.FindElement(By.XPath("//*[@id='ajax-prop-details-" + objectid + "']"))
.FindElements(By.XPath(".//span[@class='list_props']/")).ToList();
foreach(var ca in props)
{
Console.WriteLine("> " + ca.Text);
var attribs = ca.FindElements(By.XPath(".//following-sibling::")).ToList();
foreach (var atrb in attribs)
{
Console.WriteLine(">> " + atrb.Text);
}
}