[英]error is “selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable”
I want to upload an excel file on " https://www.onlinedoctranslator.com/translationform " but I'm getting the following error我想在“ https://www.onlinedoctranslator.com/translationform ”上上传 excel 文件,但出现以下错误
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable" selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互”
from selenium import webdriver
import time
driver = webdriver.Chrome('D:\Nitin_Data\chrom_driver\chromedriver.exe')
driver.maximize_window()
driver.get('https://www.onlinedoctranslator.com/translationform')
filepath = 'excel file path here'
upload_file = driver.find_element_by_xpath("//div[@class='dz-message
needsclick']")
upload_file.send_keys(filepath)
time.sleep(5)
driver.quit()
This is a bit of a hack, but I've used it in the past with success.这有点小技巧,但我过去曾成功使用过它。 You could try locating the file input
element on the page and running some Javascript to make it visible, then sends your file path text there.您可以尝试在页面上找到文件input
元素并运行一些 Javascript 使其可见,然后将您的文件路径文本发送到那里。
file_input = driver.find_element_by_xpath("//input[@type='file']")
driver.execute_script("arguments[0].style.display = 'block';", file_input)
file_input.send_keys(filepath)
If display: block
does not work, you could try toggling the visiblity:如果display: block
不起作用,您可以尝试切换可见性:
driver.execute_script("arguments[0].style.visibility= 'visible';", file_input)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.