您的位置:首页 > 其它

selenium API 随记

2016-07-04 17:34 239 查看

webdriver

查找元素

find_element_by_id

find_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]


获取内容

操作注释
getLoads a web page in the current browser session.
titleReturns the title of the current page.
current_urlGets the URL of the current page.
page_sourceGets 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_pngGets the screenshot of the current window as a binary data.
get_screenshot_as_base64Gets 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_typesGets a list of the available log types

窗口操作

操作注释
closeCloses the current window.
quitQuits the driver and closes every associated window.
current_window_handleReturns the handle of the current window.
window_handlesReturns the handles of all windows within the current session.
maximize_windowMaximizes 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_cookiesDelete 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_timeoutSet the amount of time that the script should wait during an execute_async_script call before throwing an error.
set_page_load_timeoutSet the amount of time to wait for a page load to complete before throwing an error.

webelement

操作注释
tag_nameThis element’s
tagName
property.
textThe text of the element.
clickClicks the element.
submitSubmits a form.
clearClears 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,
None
is returned.
is_selectedReturns whether the element is selected. Can be used to check if a checkbox or radio button is selected.
is_enabledReturns 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.
sizeThe size of the element.
value_of_css_propertyThe value of a CSS property.
locationThe location of the element in the renderable canvas.
rectA dictionary with the size and location of the element.
screenshot_as_base64Gets the screenshot of the current element as a base64 encoded string.
screenshot_as_pngGets the screenshot of the current element as a binary data.
screenshotGets the screenshot of the current element. Returns False if there is any IOError, else returns True. Use full paths in your filename.
parentInternal reference to the WebDriver instance this element was found from.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  selenium