Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法单击显示在两行中的表格单元格中的链接_C#_Selenium_Selenium Webdriver_Nunit - Fatal编程技术网

C# 无法单击显示在两行中的表格单元格中的链接

C# 无法单击显示在两行中的表格单元格中的链接,c#,selenium,selenium-webdriver,nunit,C#,Selenium,Selenium Webdriver,Nunit,我正在使用NUnit框架和C#自动化一个应用程序。 使用下面的代码,我可以找到并单击一个元素,整个链接文本显示在一行中(例如:abcd)。但如果链接显示为两行(例如:abcd\nxyz),则无法单击该链接 //搜索并单击名称链接 IWebElement table1=driver.FindElement(By.XPath(“//*[@id='tblsearchaudenceresults']/tbody”); IList rowCollection=table1.FindElements(按.

我正在使用NUnit框架和C#自动化一个应用程序。 使用下面的代码,我可以找到并单击一个元素,整个链接文本显示在一行中(例如:abcd)。但如果链接显示为两行(例如:abcd\nxyz),则无法单击该链接

//搜索并单击名称链接

IWebElement table1=driver.FindElement(By.XPath(“//*[@id='tblsearchaudenceresults']/tbody”);
IList rowCollection=table1.FindElements(按.TagName(“tr”));
foreach(行集合中的IWebElement行)
{
IList colItem=row.FindElements(按.TagName(“td”));
Console.WriteLine(“TA名称:+colItem[1].Text”);
if(colItem[1].Text.Equals(audienceName))
{
控制台写入线(“内部If”);
colItem[1]。单击();
Console.WriteLine(“点击链接”);
打破
}                            
}

尝试单击锚元素而不是
td
——例如-

<table>
<tr>
  <td><a href="reftosomelink">Sample long text which is multiline</a></td>
  <td>Some other label</td> 
  <td>50</td>
</tr>
</table>

如果这也不起作用,请发布您的html和错误。

请发布表格单元格文本或其html代码。您不需要在所有这些单元格和行中循环。使用XPath选择器-如果您使用的是现代浏览器,那么它将比这更高效。请参阅此链接,它可能会帮助您:)
<table>
<tr>
  <td><a href="reftosomelink">Sample long text which is multiline</a></td>
  <td>Some other label</td> 
  <td>50</td>
</tr>
</table>
row.FindElement(By.xpath("./td[1]/a")).click();