【问题标题】:Not able to upload photo by automotion on tumblr platform无法在 tumblr 平台上通过 automotion 上传照片
【发布时间】:2021-07-02 05:25:49
【问题描述】:

PFB 我在 Tumblr 上的 Autopost 代码请更正我的 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 没有定义,请任何人给我你的想法。

【问题讨论】:

  • 你遇到了什么错误?
  • selenium.common.exceptions.NoSuchElementException: 消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//*[@id="row -0"]/div/div/div[1]/button[1]/span/input"}(会话信息:chrome=89.0.4389.114)
  • @RamDayal : 请将输入元素的相关 HTML 连同父标签一起发布。
  • 你能试试这个吗? img_upload = driver.find_element_by_xpath("//input[@type='file'][@name='photo']")img_upload.send_keys("C:\\Users\\Pictures\\Logo.jpg")
  • @Madhan:我面临以下错误 -selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”:” //输入[@type='file'][@name='photo']"}(会话信息:chrome=89.0.4389.114)

标签: python python-3.x selenium automation


【解决方案1】:

据我所知,问题在于您上传文件的元素的 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(),这样程序与时间更一致,而不是仅仅等待特定的时间,以防加载时间超过预期。

【讨论】:

  • 我面临以下错误 - 文件“C:\Users\Ram\PycharmProjects\pythonProject\Auto Post\test.py”,第 33 行,在 中上传 = WebDriverWait(driver, 20) .until(EC.visibility_of_element_located((By.XPATH, "//input[@type='file']"))) 文件 "C:\Users\Ram\PycharmProjects\pythonProject\Auto Post\venv\lib\site- packages\selenium\webdriver\support\wait.py",第 80 行,直到引发 TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
  • 我看到的唯一选择是元素位于 iframe 内,您需要切换到该 iframe。从您发布的 HTML 中我看不到任何内容,但您需要提供更多信息才能知道这一点,
猜你喜欢
  • 2012-03-12
  • 1970-01-01
  • 2011-02-21
  • 1970-01-01
  • 2020-05-29
  • 1970-01-01
  • 1970-01-01
  • 2018-02-18
  • 2020-05-21
相关资源
最近更新 更多