使用selenium

时间:2018-06-10 09:05:15

标签: c# selenium

我试图从linktext获取名称或href,但没有办法。

我能够点击它,但不能在字符串中获取名称或href;

var linkElems = driver.FindElements(By.ClassName("  sorting_1"));
for (int i = 0; i < linkElems.Count; i++)
   {
        IWebElement tableElement2 = driver.FindElement(By.LinkText(linkElems[i].Text.ToString()));
        tableElement2.Click();
   }

Get the name or the href from a tag

<a href="#" name="42710962" alt="Click to open details in new window" onclick="window.open('/OTCS/llisapi.dll?func=ll&amp;objid=11743301&amp;objAction=RunReport&amp;SearchView=1&amp;PROCESSID=42710962&amp;ProjCode=0401-BIM','Document_Details','resizable=yes,scrollbars=yes,width=700px,height=600')">Architectura001</a>

请有办法获取名称或href。

1 个答案:

答案 0 :(得分:0)

无需获取文本然后单击它。链接文本定位器将自动执行该操作。请在下方使用。

driver.FindElement(By.LinkText(linkElems[i].ToString()));

编辑

如你所说,你想要一个可以通过

找到的属性值
tableElement2.GetAttribute("name");

这将返回42710962