Reputation: 1906
I am trying to search all the div
under specified XPath
with div id
. div id
gets randomly generated and not fix so searching with partial id method as some text of div id
is constant._ariaId_
is id which will be constant and numbers will get attached to it's trail.
HTML page code.
//some more HTML code before this. Trimmed for clarity.
<div tabindex="-1" data-convid="AAQkADBjMGZiZGFlLTE4ZmEtNGRlOS1iMjllLTJmOGZkNGRhZmIzNQAQAOTK5G8Pok9JkIMV8KU8bI4="
data-time="2017-03-01T20:35:37+05:30" id="_ariaId_299">
</div>
<div tabindex="-1" data-convid="AAQkADBjMGZiZGFlLTE4ZmEtNGRlOS1iMjllLTJmOGZkNGRhZmIzNQAQAOTK5G8Pok9JkIMV8KU8bI4="
data-time="2017-03-01T20:29:41+05:30" id="_ariaId_281">
</div>
<div tabindex="-1" data-convid="AAQkADBjMGZiZGFlLTE4ZmEtNGRlOS1iMjllLTJmOGZkNGRhZmIzNQAQAHnhaFwb40sGj+pN9p736NE="
data-time="2017-03-01T20:25:14+05:30" id="_ariaId_271">
The code I'm using to fetch all data matching the search criteria which will also include div id
.
IWebElement baseTable = driverGC.FindElement(By.ClassName("conductorContent"));
// gets all table rows
ICollection<IWebElement> rows = baseTable.FindElements
(By.XPath("//*[@id='primaryContainer']/div[5]/div/div[1]/div/div[4]/div[3]
/div/div[1]/div/div/div/div[5]/div[4]/div[1]/div[3]/div[1]/div/div/div[2]
/div[starts-with(@id, '_ariaId_')]"));
foreach (var row in rows)
{
//Do something....
}
This is giving me the desired multiple div
which satisfy the condition BUT
I am getting incorrect id
Expected
Current
While debugging getting below data in id.
I'm stuck on this with no clue from where these ids
coming from. Other fields are getting correctly.
Upvotes: 0
Views: 85
Reputation: 1233
The {Element(id=0.0xxxxxx)}
you are seeing is not the id of HTML element, but the id of IWebElement.
If you want to fetch the id's of all individual HTML elements, try this
foreach(var row in rows)
{
string elementID = row.GetAttribute("id");
}
Upvotes: 2