WebDriver 编辑
WebDriver is a remote control interface that enables introspection and control of user agents. It provides a platform- and language-neutral wire protocol as a way for out-of-process programs to remotely instruct the behavior of web browsers.
To have the ability to write instruction sets that can be run interchangeably in many browsers on different platforms is critical to deliver a consistent experience to users. With the new wave of developments on the web platform, the increase diversity in devices and demands for real interoperability between the technologies, WebDriver provides tooling for cross-browser testing.
Provided is a set of interfaces to discover and manipulate DOM elements in web documents and to control the behavior of a user agent. It is primarily intended to allow web authors to write tests that automate a user agent from a separate controlling process, but may also be used in such a way as to allow in-browser scripts to control a — possibly separate — browser.
Usage
So what does WebDriver let you do and what does it look like? Since WebDriver is programming language neutral, the answer to this question depends on which WebDriver client you’re using and the choice of language.
But using a popular client written in Python, your interaction with WebDriver might look like this:
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.expected_conditions import presence_of_element_located wait = WebDriverWait(driver, 10) with webdriver.Firefox() as driver: driver.get("http://google.com/ncr") driver.find_element_by_name("q").send_keys("cheese" + Keys.RETURN) wait.until(presence_of_element_located((By.CSS_SELECTOR, "h3>a"))) results = driver.find_elements_by_css_selector("h3>a") for i, result in results.iteritems(): print("#{}: {} ({})".format(i, result.text, result.get_property("href")))
This might produce output akin to this:
#1 Cheese - Wikipedia (https://en.wikipedia.org/wiki/Cheese)
Reference
Commands
- Close Window
- Get Element Attribute
- Get Element Property
- Get Element Tag Name
- Get Timeouts
- Get Window Handles
- Get Window Rect
- New Window
- Set Timeouts
- Set Window Rect
Types
Capabilities
Errors
- Insecure certificate
- Invalid argument
- Invalid cookie domain
- Invalid selector
- Invalid session ID
- Javascript error
- Script timeout
- Stale element reference
- Unknown command
- Unknown error
- Unknown method
Specifications
Specification | Status | Comment |
---|---|---|
WebDriver | Living Standard | Initial definition |
Browser compatibility
BCD tables only load in the browser
See also
- Cross browser testing
- Selenium documentation (work in progress)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论