C#应用Selenium学习:获取网页元素的方法

1、根据ID

IWebElement FindElementById(string id)

2、根据链接文本

IWebElement FindElementByLinkText(string linkText);

3、根据元素内容

IWebElement FindElementByXPath(string xpath);
//例子
this.Driver.FindElementByXPath($"//*[text()=\"{xpath}\"]");

4、根据类名。需要说明的是,之所以使用CSS Selector方法,是为了应对className中间有空格的情况

IWebElement FindElementByCssSelector(string cssSelector);
//示例
this.Driver.FindElementByCssSelector($"[class=\"{className}\"]");

5、根据标签名字

IWebElement FindElementByTagName(string tagName);

 

posted @ 2021-02-12 10:08  顺其自然,道法自然  阅读(1039)  评论(0编辑  收藏  举报