I want to verify the values from a register by using a css selector
[FindsBy(How = How.CssSelector, Using = "#grid_cases > table > tbody")]
private IWebElement CaseListGrid;
I have to return the WebElements value and store it to string
public List<CaseListEntry> GetCaseListEntries()
{
CaseListGrid.
return null;
}
You can get the text from your CaseListGrid element by using the following:
CaseListGrid.Text;
But you are retrieving a tbody, which probably doesn't have any text in it.
After you retrieved the CaseListGrid element, you could do something like this to retrieve all td
tags inside the tbody.
CaseListGrid.FindElements(By.TagName("td"));
After that, loop over the elements and retrieve the text:
public List<CaseListEntry> GetCaseListEntries()
{
var elements = CaseListGrid.FindElements(By.TagName("td"));
var listEntries = new List<CaseListEntry>();
foreach (var element in elements)
{
var text = element.Text;
if (!string.IsNullOrWhiteSpace(text))
listEntries.Add(new CaseListEntry(text)); // I don't know what kind of class CaseListEntry is, so this is pseudo code
}
return listEntries;
}
It works
var CaseGridTrs = CaseListGrid.FindElements(By.XPath(".//tr"));
var entryList = CaseGridTrs.Select(x =>
{
var CaseEntryTds = x.FindElements(By.XPath(".//td"));
return new CaseListEntry
{ Register = CaseEntryTds.ElementAt(0).FindElement(By.XPath(".//a")).Text,
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.