Automagica小试

时间:2022-07-23
本文章向大家介绍Automagica小试,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

一、概述

Automagica 是一个开源智能机器人流程自动化(SRPA,Smart Robotic Process Automation)平台,借助 Automagica 的python 函数库,可以通过简单程序脚本实现打开各种应用程序并对应用进行操作的功能,使自动化跨平台流程变得轻而易举。

环境要求

Automagica 需要 Python 3.7 环境,官方支持 Windows 10 平台,Linux 和 Mac 目前官方还不支持。

安装

pip3 install automagica
pip3 install selenium

下文的demo会用到selenium,因此先安装一下。

二、演示

业务场景

实验案例的业务场景是:自动打开Chrome浏览器,跳转到百度首页,然后检索关键字“automagica”。

chromedriver安装

查看浏览器版本

1. 打开谷歌浏览器, 在地址栏输入 chrome://version/ 查看版本信息:

2. 选择合适版本的驱动下载

下载地址:http://chromedriver.storage.googleapis.com/index.html

 由于我的版本为:75.0.3770.100,但是这里并没有与之对应的版本。因此选择小一点的版本,也就是:75.0.3770.90

3. 解压下载的驱动放到指定目录,代码调用时指定该目录即可。

这里,我将chromedriver.exe放到路径 E:virtualenvdjango下面。

完整代码

test1.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-


# 引用automagica的核心库,鼠标、键盘、浏览器、系统应用、Office、PDF等操作函数,都依赖于该模块。
from automagica import *
# 引入selenium 模块
from selenium import webdriver

# chromedriver 驱动路径
chrome_driver = r"E:virtualenvdjangochromedriver.exe"
# #创建chrome浏览器实例,指定驱动
browser = webdriver.Chrome(executable_path=chrome_driver)
# 打开百度
browser.get('https://baidu.com/')
# 获取搜索输入框,嵌入关键字automagica
search_input = browser.find_element_by_name('wd')
search_input.send_keys("automagica")
# 获取检索按钮,点击
search_btn = browser.find_element_by_id('su')
search_btn.click()

注意:这里必须指定chromedriver 驱动路径,否则会出现错误:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

虽然我尝试将此路径加入到windows 环境变量pah中,但测试之后,还是会报错。

运行代码,效果如下:

本文参考链接:

https://www.cnblogs.com/vikezhu/p/12343982.html

https://blog.csdn.net/weixin_43746433/article/details/95237254