C# 在C中逐个重定向到HTML表的特定列中存在的每个链接#
我从数据表的网页中检索了一个表,或者简单地说,我有一个表,其中第一列包含不同的名称,所有这些名称都是超链接。现在我的要求是,我需要在C#或编码ui中逐个单击每个名称。我如何才能做到这一点?它看起来像这样:C# 在C中逐个重定向到HTML表的特定列中存在的每个链接#,c#,coded-ui-tests,C#,Coded Ui Tests,我从数据表的网页中检索了一个表,或者简单地说,我有一个表,其中第一列包含不同的名称,所有这些名称都是超链接。现在我的要求是,我需要在C#或编码ui中逐个单击每个名称。我如何才能做到这一点?它看起来像这样: [TestMethod] public async Task TestAllTheLinks() { BrowserWindow browserWindow = BrowserWindow.Launch("mywebsiteurl"); HtmlTable table = n
[TestMethod]
public async Task TestAllTheLinks()
{
BrowserWindow browserWindow = BrowserWindow.Launch("mywebsiteurl");
HtmlTable table = new HtmlTable(browserWindow);
table.SearchProperties.Add(HtmlTable.PropertyNames.Id, "tableId"); // or other search properties
List<Exception> failureLinks = new List<Exception>();
using (var client = new HttpClient())
{
for(int rowIndex = 0, max = table.RowCount; rowIndex < max; rowIndex++)
{
HtmlCell tableCell = table.GetCell(rowIndex, 0);
HtmlHyperlink link = new HtmlHyperlink(tableCell);
// are you sure you want to click?
// how are you going to test rest of links if you nav away?
Mouse.Click(link);
// or would you rather just send an http request to that url to see if it is successful
string href = link.Href;
var result = await client.GetAsync(href);
if (!result.IsSuccessStatusCode)
{
failureLinks.Add(new Exception($"Link failed: {href}"));
}
}
}
if(failureLinks.Any()){
throw new AggregateException(failureLinks);
}
}
[TestMethod]
公共异步任务TestAllTheLinks()
{
BrowserWindow=BrowserWindow.Launch(“mywebsiteurl”);
HtmlTable=新HtmlTable(浏览器窗口);
table.SearchProperties.Add(HtmlTable.PropertyNames.Id,“tableId”);//或其他搜索属性
列表失败链接=新列表();
使用(var client=new HttpClient())
{
对于(int rowIndex=0,max=table.RowCount;rowIndex
到目前为止,您尝试了什么?请先尝试解决这个问题,发布您尝试过的代码,以及不起作用的代码。一旦你做到了,我们可以更好地帮助你。