selenium API 随记
2016-07-04 17:34
239 查看
webdriver
查找元素
find_element_by_idfind_element_by_xpath
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_name
find_element_by_tag_name
find_element_by_class_name
find_element_by_css_selector
所有的以上操作,都有查找多个元素的对应操作
find_elements_by_[option]
获取内容
操作 | 注释 |
---|---|
get | Loads a web page in the current browser session. |
title | Returns the title of the current page. |
current_url | Gets the URL of the current page. |
page_source | Gets the source of the current page. |
get_screenshot_as_file(filename) | Gets the screenshot of the current window. Returns False if there is any IOError, else returns True. Use full paths in your filename. |
get_screenshot_as_png | Gets the screenshot of the current window as a binary data. |
get_screenshot_as_base64 | Gets the screenshot of the current window as a base64 encoded string which is useful in embedded images in HTML. |
get_log(log_type) | Gets the log for a given log type |
log_types | Gets a list of the available log types |
窗口操作
操作 | 注释 |
---|---|
close | Closes the current window. |
quit | Quits the driver and closes every associated window. |
current_window_handle | Returns the handle of the current window. |
window_handles | Returns the handles of all windows within the current session. |
maximize_window | Maximizes the current window that webdriver is using |
执行js脚本
操作 | 注释 |
---|---|
execute_script(script, *args) | Synchronously Executes JavaScript in the current window/frame. - script: The JavaScript to execute. - *args: Any applicable arguments for your JavaScript. |
execute_async_script(script, *args) | Asynchronously Executes JavaScript in the current window/frame. |
cookie相关
操作 | 注释 |
---|---|
get_cookie(name) | Get a single cookie by name. Returns the cookie if found, None if not. |
delete_cookie(name) | Deletes a single cookie with the given name. |
delete_all_cookies | Delete all cookies in the scope of the session. |
add_cookie(cookie_dict) | Adds a cookie to your current session. - cookie_dict: A dictionary object, with required keys - “name” and “value”; optional keys - “path”, “domain”, “secure”, “expiry” |
超时设置
操作 | 注释 |
---|---|
implicitly_wait(time_to_wait) | Sets a sticky timeout to implicitly wait for an element to be found, or a command to complete. This method only needs to be called one time per session. To set the timeout for calls to execute_async_script, see set_script_timeout. |
set_script_timeout | Set the amount of time that the script should wait during an execute_async_script call before throwing an error. |
set_page_load_timeout | Set the amount of time to wait for a page load to complete before throwing an error. |
webelement
操作 | 注释 |
---|---|
tag_name | This element’s tagNameproperty. |
text | The text of the element. |
click | Clicks the element. |
submit | Submits a form. |
clear | Clears the text if it’s a text entry element. |
get_attribute(name) | Gets the given attribute or property of the element. name - Name of the attribute/property to retrieve. If there’s no attribute with that name, Noneis returned. |
is_selected | Returns whether the element is selected. Can be used to check if a checkbox or radio button is selected. |
is_enabled | Returns whether the element is enabled. |
find_element_by_[option] | Finds element within this element’s children by option |
send_keys(value) | Simulates typing into the element. - value - A string for typing, or setting form fields. For setting file inputs, this could be a local file path. |
size | The size of the element. |
value_of_css_property | The value of a CSS property. |
location | The location of the element in the renderable canvas. |
rect | A dictionary with the size and location of the element. |
screenshot_as_base64 | Gets the screenshot of the current element as a base64 encoded string. |
screenshot_as_png | Gets the screenshot of the current element as a binary data. |
screenshot | Gets the screenshot of the current element. Returns False if there is any IOError, else returns True. Use full paths in your filename. |
parent | Internal reference to the WebDriver instance this element was found from. |
相关文章推荐
- 针对Ruby的Selenium WebDriver安装指南
- Selenium处理select标签的下拉框
- python结合selenium获取XX省交通违章数据的实现思路及代码
- Python中使用 Selenium 实现网页截图实例
- selenium grid2 初探
- UI自动化测试框架之Selenium关键字驱动
- selenium使用chrome时,报错ignore certificate errors
- python结合selenium获取XX省交通违章数据的实现思路及代码
- 利用 Selenium 自动化 web 测试
- Xampp安装PHPUnit
- selenium学习3 selenium for IE8+WIN7
- Selenium官文翻译--(一)目录
- Selenium官文翻译--(二)Selenium WebDriver(未完待续)
- 2016年的自动化测试趋势
- Selenium关于下拉列表的定位方法总结
- selenium webdriver 学习总结-元素定位
- 用C#.NET 与Webdriver写的抓取网页信息的小工具
- [selenium + eclipse + testng]Build environment
- selenium-ide安装与使用
- selenium学习笔记(1)--webdriver中时间控件的使用