首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在python中设置Auto IT的路径

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

Stack Overflow用户
提问于 2021-07-20 15:54:28
回答 1查看 43关注 0票数 0

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

代码语言:javascript
运行
复制
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

下面是我写的代码:

代码语言:javascript
运行
复制
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()
EN

回答 1

Stack Overflow用户

发布于 2021-08-02 00:13:21

下面是一个使用https://www.autoitscript.com/forum/index.php?showtopic=153520的自动生成示例

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

代码语言:javascript
运行
复制
#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, "title:=(Max 25 files, 10 GB per file);ControlType:=UIA_TextControlTypeId", $treescope_subtree)
_UIA_Action($oUIElement, "setfocus")
_UIA_Action($oUIElement, "highlight")
_UIA_Action($oUIElement, "activate")
_UIA_Action($oUIElement, "leftclick")


Func MyExit()
    Exit
EndFunc   ;==>MyExit
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68451395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档