国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Selenium API (C#)

Selenium API (C#)

1 Fetching a Page

driver.Url = "http://www.google.com";

2 Locating UI Elements (WebElements)?

By ID?

This is the most efficient and preferred way to locate an element. Common pitfalls that UI developers make is having non-unique id’s on a page or auto-generating the id, both should be avoided. A class on an html element is more appropriate than an auto-generated id.

Example of how to find an element that looks like this:

<div id="coolestWidgetEvah">...</div>

IWebElement element = driver.FindElement(By.Id("coolestWidgetEvah"));

 

By Class Name?

“Class” in this case refers to the attribute on the DOM element. Often in practical use there are many DOM elements with the same class name, thus finding multiple elements becomes the more practical option over finding the first element.

Example of how to find an element that looks like this:

<div class="cheese"><span>Cheddar</span></div><div class="cheese"><span>Gouda</span></div>

IList<IWebElement> cheeses = driver.FindElements(By.ClassName("cheese"));

 

By Tag Name?

The DOM Tag Name of the element.

Example of how to find an element that looks like this:

<iframe src="..."></iframe>
IWebElement frame = driver.FindElement(By.TagName("iframe"));

By Link Text?

Find the link element with matching visible text.

Example of how to find an element that looks like this:

<a >cheese</a>
IWebElement cheese = driver.FindElement(By.LinkText("cheese"));

By CSS?

Like the name implies it is a locator strategy by css. Native browser support is used by default, so please refer to w3c css selectors <http://www.w3.org/TR/CSS/#selectors>for a list of generally available css selectors. If a browser does not have native support for css queries, then Sizzle is used. IE 6,7 and FF3.0 currently use Sizzle as the css query engine.

Beware that not all browsers were created equal, some css that might work in one version may not work in another.

Example of to find the cheese below:

<div id="food"><span class="dairy">milk</span><span class="dairy aged">cheese</span
IWebElement cheese = driver.FindElement(By.CssSelector("#food span.dairy.aged"));

By XPATH?

At a high level, WebDriver uses a browser’s native XPath capabilities wherever possible. On those browsers that don’t have native XPath support, we have provided our own implementation. This can lead to some unexpected behaviour unless you are aware of the differences in the various xpath engines.

DriverTag and Attribute NameAttribute ValuesNative XPath Support
HtmlUnit DriverLower-casedAs they appear in the HTMLYes
Internet Explorer DriverLower-casedAs they appear in the HTMLNo
Firefox DriverCase insensitiveAs they appear in the HTMLYes

This is a little abstract, so for the following piece of HTML:

<input type="text" name="example" /><INPUT type="text" name="other" />
IList<IWebElement> inputs = driver.FindElements(By.XPath("http://input"));

Using JavaScript?

You can execute arbitrary javascript to find an element and as long as you return a DOM Element, it will be automatically converted to a WebElement object.

Simple example on a page that has jQuery loaded:

 
IWebElement element = (IWebElement) ((IJavaScriptExecutor)driver).ExecuteScript("return $('.cheese')[0]");

 

 

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Selenium(四)——webdriver 之定位頁面元素
[小北De編程手記] : Lesson 03
Selenium2.0之WebDriver學習總結(jié)(2)
Python爬蟲(二十一)
python selenium元素定位——8種方法
用python
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服