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

时间:2021-02-16 11:49:48   收藏:0   阅读:0

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);

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!