[英]import file from folder using selenium for python
使用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:消息:未知錯誤:無法聚焦元素。
我嘗試單擊element,因為我注意到頁面上有td class =“ hide”,我認為這可能是導致問題的原因。 任何建議,將不勝感激!
您可以嘗試以下方法:
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()
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.