[英]Print text of elements from an list in C#
我必須打印 web 元素的所有文本,所以我將 web 元素存儲在列表“測試”中,然后獲取每個 web 元素的文本並繼續添加到其他列表“標題”。 現在,當我嘗試打印列表“標題”的所有元素時。但只打印第一個元素的文本。 請幫我找出我哪里出錯了。
public void PrintText()
{
var Title = new List<string>();
IList <IWebElement> test=Controls.GetWebElementList(X-path);
foreach (var g in test)
{
Title.Add(Controls.GetText(x-path));
}
foreach (var h in Title)
{
Console.WriteLine(h);
}
}
尚不清楚Controls.GetWebElementList()
是如何定義的。
理想情況下,要提取文本,您必須為VisibilityOfAllElementsLocatedBy()
誘導WebDriverWait ,並且可以使用以下定位器策略:
IList <IWebElement> test = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.XPath("X-path")));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.