导航

Helium文档11-WebUI自动化-attach_file上传文件或图片

Posted on 2020-09-02 07:07  weitungblog  阅读(778)  评论(0编辑  收藏  举报

前言

attach_file关键字根据官方介绍的作用是上传文件

入参介绍

def attach_file(file_path, to=None):
"""
:param file_path: The path of the file to be attached.
:param to: The file input element to which the file should be attached.

Allows attaching a file to a file input element. For instance::

attach_file("c:/test.txt", to="Please select a file:")

The file input element is identified by its label. If you omit the ``to=``
parameter, then Helium attaches the file to the first file input element it
finds on the page.
"""

 

举例说明

1、用博客园的上传图片页面举例,当页面上只有一个上传页面的时候可以这么写:

attach_file(r"c:\\1.jpg")

 

部分页面的上传按钮不是原生的按钮,需要隐藏其calss

需要使用selenium执行js代码来实现

 

 

欢迎交流

310678696