Selenium文件上传

https://www.selenium.dev/documentation/webdriver/elements/file_upload/

用的方法就是element.send_keys(),

from selenium import webdriver
driver.implicitly_wait(10)
driver.get("https://the-internet.herokuapp.com/upload");
driver.find_element(By.ID,"file-upload").send_keys("selenium-snapshot.jpg")
driver.find_element(By.ID,"file-submit").submit()
if(driver.page_source.find("File Uploaded!")):
    print("file upload success")
else:
    print("file upload not successful")
driver.quit()

posted @ 2023-07-17 11:26  蕝戀  阅读(10)  评论(0编辑  收藏  举报