微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在python中设置Auto IT的路径

如何解决如何在python中设置Auto IT的路径

我想使用 selenium 和 python 通过 auto it 库自动上传文件,但在执行代码时出现以下错误

from .autoit import options,properties,commands
  File "C:\Users\garima.madaan\PycharmProjects\TestPythonProject\venv\lib\site-packages\autoit\autoit.py",line 26,in <module>
    raise IOError("Cannot load AutoItX from path: %s" % dll_path)
OSError: Cannot load AutoItX from path: C:\Users\garima.madaan\PycharmProjects\TestPythonProject\venv\lib\site-packages\autoit\lib\AutoItX3.dll

Process finished with exit code 1

这是我写的代码

from selenium import webdriver
from selenium.webdriver.common.by import By
import autoit
import time

class Upload():

    def test(self):
        baseurl = 'https://easyupload.io/'
        driver = webdriver.Chrome()
        driver.get(baseurl)
        driver.maximize_window()
        driver.implicitly_wait(30)
        time.sleep(5)
        driver.execute_script("window.scrollBy(0,300);")
        time.sleep(5)

        #click on click here to drop files
        element1= driver.find_element(By.XPATH,"//div[@class='upload-section']/form/div/button")
        element1.click()
        time.sleep(5)

        #select a file using autoit
        autoit.win_wait_active("Open")
        driver.close()

a= Upload()
a.test()

解决方法

这是一个使用 https://www.autoitscript.com/forum/index.php?showtopic=153520

的 Autoit 示例

我希望有人觉得这很有用。

#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <EditConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPISysWin.au3>
#include <AD.au3>
#include <Array.au3>
#include "UIAWrappers.au3"
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <GuiListBox.au3>
#include <Word.au3>
#include <File.au3>
#include <Excel.au3>


Opt("WinWaitDelay",150)
Opt("WinTitleMatchMode",2)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",2)
Opt("SendKeyDelay",10)
Opt("GUIResizeMode",1)
HotKeySet("^!x","MyExit")

Global  $Web,$hWnd

$Web = "https://easyupload.io/"

ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe","--new-window --force-renderer-accessibility " & $Web,"","")
WinWait("Easyupload.io - Upload files for free and transfer big files easily. - Google Chrome",8)
$hWnd = WinGetHandle("Easyupload.io - Upload files for free and transfer big files easily. - Google Chrome")
WinActivate($hWnd)
WinSetState($hWnd,@SW_MAXIMIZE)
;Sleep(7000); Give time for the webpage to load (out of country)
Local $oP6=_UIA_getObjectByFindAll($UIA_oDesktop,"Title:=Easyupload.io - Upload files for free and transfer big files easily. - Google Chrome;controltype:=UIA_PaneControlTypeId;class:=Chrome_WidgetWin_1",$treescope_children)
_UIA_Action($oP6,"setfocus")
Local $oP5=_UIA_getObjectByFindAll($oP6,"Title:=Easyupload.io - Upload files for free and transfer big files easily.;controltype:=UIA_DocumentControlTypeId;class:=Chrome_RenderWidgetHostHWND",$treescope_children)
_UIA_Action($oP5,"setfocus")

;~ First find the object in the parent before you can do something
Local $oUIElement=_UIA_getObjectByFindAll("(Max25files,10GBperfile).mainwindow","title:=(Max 25 files,10 GB per file);ControlType:=UIA_TextControlTypeId",$treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP5,$treescope_subtree)
_UIA_Action($oUIElement,"setfocus")
_UIA_Action($oUIElement,"highlight")
_UIA_Action($oUIElement,"activate")
_UIA_Action($oUIElement,"leftclick")


Func MyExit()
    Exit
EndFunc   ;==>MyExit

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?