无法在 tumblr 平台上通过 automotion 上传照片

Not able to upload photo by automotion on tumblr platform

PFB 我在 Tumblr 上的自动发布代码请更正我的 28 号。行

from selenium import webdriver
import pyautogui
import time


email = "Email"
passwd = "Password"


PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.maximize_window()
time.sleep(2)

driver.get("https://www.tumblr.com/login")
time.sleep(2)
driver.find_elements_by_xpath('//*[@id="base-container"]/div[2]/div/div[2]/div/section/div/form/input')
pyautogui.typewrite(email)
time.sleep(1)
pyautogui.press("Enter")
time.sleep(1)
pyautogui.typewrite(passwd)
time.sleep(2)
pyautogui.press("Enter")
time.sleep(4)
driver.find_element_by_xpath('//*[@id="base-container"]/div[2]/div[2]/div[1]/main/div[3]/ul/li[2]/button/span').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="row-0"]/div/div/div[1]/button[1]/span/input').click()
time.sleep(5)

下一行错误 -

driver.find_element_by_xpath('//*[@id="row-0"]/div/div/div[1]/button[1]/span/input').click()

可能是iframe没有定义,请大家出出主意。

据我所知,问题出在您上传文件的元素的 XPATH 上。

尝试这样的事情:

# First make sure to import expected_conditions as EC

from selenium.webdriver.support import expected_conditions as EC

upload = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@type='file'])))

upload.send_keys("/path/to/your/image")

此外,我建议执行 WebDriverWait 而不是 time.sleep(),这样程序与时间更加一致,而不是仅仅等待特定的时间,以防需要更长的时间超出预期加载。