[英]How to set path of Auto IT in python
我想使用 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, "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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.