


This article mainly introduces the file upload function implemented by python+selenium+autoit. Friends who need it can refer to it
Question
When automating the UI layer on the web side, you will encounter file upload operations. Friends often ask, here is a summary
Solution
The first type: Upload files of type=file, similar to the following
Use code similar to this to complete:
driver.find_element('name','file').send_keys('./小强测试品牌.png')
The second type: except for the first type, it is more troublesome to implement. Autoit is used here. The general steps are as follows:
1. Download and install autoit, and then you can see it in the start menu. Go to the following
AutoIt Windows Info is used to identify Windows control information
Compile Script to.exe is used to generate an exe execution file from AutoIt
Run Script is used to execute AutoIt scripts
SciTE Script Editor is used to write AutoIt scripts
2. The upload function is as follows
3. The identification elements, mainly the file name input box and the open button in the picture above, are completed using AutoIt Windows Info. The recording results are as follows:
The class of the file name input box is "Edit" and the Instance is "1"
The class of the open button is "Button" and the Instance is "1"
4. Write a script using SciTE Script Editor. The content is as follows:
ControlFocus("文件上传", "","Edit1") WinWait("[CLASS:#32770]","",10) ControlSetText("文件上传", "", "Edit1","D:python_workspaceQiangSEAutopic小强测试品牌.jpg") Sleep(2000) ControlClick("文件上传", "","Button1");
In the above code, special attention should be paid to the word "File Upload" which is the title of the dialog box that pops up after you click the upload button. It may be different in each system
5. Verification script
Make sure the upload dialog box of the page is open, and then run the script tools>go
6. Open the Compile Script to.exe tool and generate it as an exe executable file
7. Call
up=self.driver.find_element('class name','avatar-uploader-trigger') up.find_element('class name','ant-btn').click() os.system('D:\python_workspace\QiangSEAuto\upload.exe') time.sleep(20)
Others
In fact, there are other solutions. If you are interested, you can research them yourself, such as You can use the following method:
Python pywin32 library to identify the dialog box handle, and then operate
SendKeys library
keybd_event to simulate keystrokes
Summarize
The above is the detailed content of Detailed graphic code explanation of how python, selenium and autoit implement the file upload function. For more information, please follow other related articles on the PHP Chinese website!

Laravel开发:如何使用LaravelDusk和Selenium进行浏览器测试?随着Web应用程序变得越来越复杂,我们需要确保其各个部分都能正常运行。浏览器测试是一种常见的测试方法,用于确保应用在各种不同浏览器下的正确性和稳定性。在Laravel开发中,可以使用LaravelDusk和Selenium进行浏览器测试。本文将介绍如何使用这两个工具进行测

1、滑块验证思路被测对象的滑块对象长这个样子。相对而言是比较简单的一种形式,需要将左侧的拼图通过下方的滑块进行拖动,嵌入到右侧空槽中,即完成验证。要自动化完成这个验证过程,关键点就在于确定滑块滑动的距离。根据上面的分析,验证的关键点在于确定滑块滑动的距离。但是看似简单的一个需求,完成起来却并不简单。如果使用自然逻辑来分析这个过程,可以拆解如下:1.定位到左侧拼图所在的位置,由于拼图的形状和大小固定,那么其实只需要定位其左边边界离背景图片的左侧距离。(实际在本例中,拼图的起始位置也是固定的,节省了

如何使用Selenium进行Web自动化测试概述:Web自动化测试是现代软件开发过程中至关重要的一环。Selenium是一个强大的自动化测试工具,可以模拟用户在Web浏览器中的操作,实现自动化的测试流程。本文将介绍如何使用Selenium进行Web自动化测试,并附带代码示例,帮助读者快速上手。环境准备在开始之前,需要安装Selenium库和Web浏览器驱动程

pycharm安装selenium步骤:1、打开PyCharm;2、在菜单栏中选择依次选择 "File"、"Settings"、"Project: [项目名称]";3、选择 Project Interpreter;4、点击选项卡右侧的"+";5、在弹出的窗口搜索selenium;6、找到selenium点击旁边的"Install"按钮;7、等待安装完成;8、关闭设置对话框即可。

随着互联网技术的飞速发展,Web应用程序越来越多地应用于我们的日常工作和生活中。而在Web应用程序开发过程中,爬取网页数据是一项非常重要的任务。虽然市面上有很多的Web抓取工具,但是这些工具的效率都不是很高。为了提高网页数据爬取的效率,我们可以利用PHP和Selenium的结合使用。首先,我们需要了解一下PHP和Selenium分别是什么。PHP是一种强大的

在Scrapy爬虫中使用Selenium和PhantomJSScrapy是Python下的一个优秀的网络爬虫框架,已经被广泛应用于各个领域中的数据采集和处理。在爬虫的实现中,有时候需要模拟浏览器操作去获取某些网站呈现的内容,这时候就需要用到Selenium和PhantomJS。Selenium是模拟人类对浏览器的操作,让我们可以自动化地进行Web应用程序测试

一.什么是Selenium网络爬虫是Python编程中一个非常有用的技巧,它可以让您自动获取网页上的数据。Selenium是一个自动化测试工具,它可以模拟用户在浏览器中的操作,比如点击按钮、填写表单等。与常用的BeautifulSoup、requests等爬虫库不同,Selenium可以处理JavaScript动态加载的内容,因此对于那些需要模拟用户交互才能获取的数据,Selenium是一个非常合适的选择。二.安装Selenium要使用Selenium,首先需要安装它。您可以使用pip命令来安装

随着互联网的发展,网络数据爬取越来越成为人们关注的焦点。网络数据爬虫可以从互联网中采集大量有用的数据,为企业、学术研究和个人分析提供支持。本文将介绍使用PHP和Selenium构建网络数据爬虫的方法和步骤。一、什么是网络数据爬虫?网络数据爬虫是指自动化程序,在互联网中采集指定网站的数据。网络数据爬虫使用不同的技术和工具来实现,其中最常用的技术是使用编程语言和


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
