|
百度页面上传图片的操作。编辑器VScode;语言:python+selenium
贴代码:
import autoit
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
import time
driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get('http://www.baidu.com')
# 点击百度上面的照相机按钮
driver.find_element(By.XPATH,'//span[@class="soutu-btn"]').click()
# 点击选择文件
ele = driver.find_element(By.XPATH,'//input[@class="upload-pic"]')
# 定义鼠标对象
action = ActionChains(driver)
# 调用鼠标事件
action.click(ele)
# 执行鼠标事件方法
action.perform()
time.sleep(3)
# 针对windows操作
# 通过autoit来获取弹出的窗口
# 窗口标题‘打开 ’,找3秒钟,找不到报错
autoit.win_wait_active("打开",3)
# autoit.win_activate('打开')
# 在文件选择输入框中输入文件的地址及文件名称
autoit.control_send('打开','Edit1',r'D:\Pictures\33.jpg')
# 在弹出窗口中点击 ’打开‘按钮
autoit.control_click('打开','Button1')
time.sleep(10)
driver.close()
报错信息:
Traceback (most recent call last):
File "c:\Users\admin\Desktop\pytest_learning\test.py", line 29, in <module>
autoit.win_wait_active("打开",3)
File "F:\Program Files\python3.8.10\lib\site-packages\autoit\autoit.py", line 84, in wrapper
raise AutoItError(err_msg)
autoit.autoit.AutoItError: timeout on wait for activate window
|
|