简体   繁体   English

错误是“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互”

[英]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.

相关问题 Selenium.common.exceptions.ElementNotInteractableException:消息:元素在离子框架中不可交互 - Selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable in ionic framework 发现 selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 - Found selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 网页抓取:selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 - Webscraping: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 获取 Selenium 错误 - selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 - Getting Selenium Error - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable 随机我收到错误:“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互:元素大小为零” - Randomly I get the error: “selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: element has zero size” 硒错误即“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互” - Selenium error namely 'selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable' Selenium 自动化测试错误:selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 - Selenium automated testing error: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable selenium.common.exceptions.ElementNotInteractableException:消息:使用Selenium和Python插入值时元素不可交互 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while inserting value using Selenium and Python selenium.common.exceptions.ElementNotInteractableException:消息:将文本发送到 contenteditable div 元素时元素不可交互 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while sending text to contenteditable div element selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互 - 尝试将 .send_keys() 发送到文本框时 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable - when trying to .send_keys() to text boxes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM