(Mac系统)web自动化+selenium+python,解决上传本地文件/图片
解决web自动化上传图片(Mac)
·
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import pyautogui
import schedule
from selenium.webdriver.common.keys import Keys
def test_yuancailiao_selenium():
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("https://mes-test.microfloats.com/dashboard/analysis")
elem = driver.find_element('id', 'loginName').send_keys("admin")
elem = driver.find_element('id', 'password').send_keys("123456")
elem = driver.find_element('xpath', '//button[@type="submit"]').click()
time.sleep(3)
elem = driver.find_element('xpath', '//h1[contains(text(),"今日采购")]//following-sibling::a').click()
driver.maximize_window()
time.sleep(3)
# 基本资料
elem = driver.find_element('xpath', '//span[contains(text(),"技术中心")]').click()
time.sleep(3)
elem = driver.find_element('xpath', '//a[@target="原材料目录管理"]').click()
time.sleep(3)
elem = driver.find_element('xpath', '//span[contains(text(),"新增")]//ancestor::button').click()
time.sleep(3)
elem = driver.find_element('xpath', '//input[@id="name"]').send_keys("原材料2")
time.sleep(3)
elem = driver.find_element('xpath', '//input[@id="materialQuality"]').send_keys("材质333")
elem = driver.find_element('xpath', '//input[@id="size"]').send_keys("&3")
elem = driver.find_element('xpath', '//div[contains(text(),"上传")]').click()
pyautogui.write('/Users/bbt/Desktop/3.jpeg')
pyautogui.press('enter', 3)
time.sleep(2)
pyautogui.moveTo(1230, 610, duration=1)
pyautogui.click()
time.sleep(2)
elem = driver.find_element('xpath', '//span[contains(text(),"确 定")]').click()
pyautogui.moveTo(1230, 610, duration=1)
# 第一个参数是左右移动像素值,第二个是上下,duration 的作用是设置移动时间
更多推荐




所有评论(0)