使用selenium for python从文件夹导入文件

问题描述 投票:0回答:1

使用Selenium for Python从网页下载文件后,我想将该文件上传到另一个页面。我一直在使用到目前为止我发现的建议解决方案,但我一直看不到元素。

这是代码:

element = driver.find_element_by_id('id_in_page')
driver.execute_script("$(arguments[0]).click();", element)
element.send_keys('path_to_folder/file_to_upload')

selenium.common.exceptions.WebDriverException:消息:未知错误:无法聚焦元素。

我试图点击元素,因为我注意到页面有一个td class =“hide”,我认为这可能导致问题。任何建议将不胜感激!

python python-2.7 selenium selenium-webdriver selenium-chromedriver
1个回答
0
投票

你可以试试这个:

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
...
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.ID, 'id_in_page')))
element = driver.find_element_by_id('id_in_page')

actions = ActionChains(driver)
actions.move_to_element(element)
actions.click()
actions.send_keys('path_to_folder/file_to_upload')
actions.perform()
...
© www.soinside.com 2019 - 2024. All rights reserved.