selenium API 随记

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.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值