0
我有元素的列表,位于硒与By.CssSelector
方法:参考硒元素中JavaScriptExecutor
var contentRows = new List<TableRow>();
for (var i = 1; i < PositiveInfinity; i++)
{
var cssSelectorToFind = $"tbody > tr:nth-child({i})";
var bySelector = By.CssSelector(cssSelectorToFind);
var rowElement = WebElement.FindElements(bySelector).ToArray();
if (rowElement.Length == 1)
{
var description = $"{Description} Content row: {i}. Selected by: {bySelector}.";
var tableRow = new TableRow(bySelector, WebDriver, description, Headers);
contentRows.Add(tableRow);
}
else
{
if (rowElement.Length == 0)
{
break;
}
else
{
throw new InvalidOperationException($"The selector {bySelector} returned more that one row at the same ordinal position. Should be impossible... Best look at the selector and the HTML.");
}
}
}
return contentRows;
对于每个这些行我需要设置一类的selected
的HTML。
据我所知,我必须用JavaScriptExecutor
来做到这一点。
- 有没有办法让每一个这样的参考,所以我可以单独添加?
- 是唯一的方法给每个行一些唯一的ID,然后在JavaScrit中使用它?