1

I'm not able to upload file from my local. Below is the code I'm using to upload file :

BrowseElement = driver.find_element(By.CSS_SELECTOR, "span[class='image-icon material-icons-round post_image-icon__37fM5']")
BrowseElement.send_keys("C://Users//deepa//Downloads//deepak_1.png")

Below is the error I'm getting :

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Please help me out.

Thanks in advance.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Deepak
  • 13
  • 3

2 Answers2

0
import os
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://www.google.com")
driver.find_element_by_name("q").send_keys("selenium python")
driver.find_element_by_name("btnK").click()

# get the current directory
current_dir = os.getcwd()

# get the file path
file_path = os.path.join(current_dir, "test.txt")

# upload the file
driver.driver.find_element_by_css_selector("file-upload").send_keys(file_path)

# close the browser
driver.close()

I generated it using https://askjarvis.io/protected/demo.html, you can also do it if it doesn't exactly answer what you are trying to do.

  • The content at https://askjarvis.io/protected/demo.html ends up behind an account-wall. This is not favorable. Please modify such its open to all. Also, add context why your solution works. Both will improve answer quality. End of Review. – ZF007 Nov 25 '21 at 10:59
0

If your web page has at least one input field with type as file, then the below code should work

BrowseElement = driver.find_element(By.CSS_SELECTOR, "input[type='file']")
BrowseElement.send_keys("C://Users//deepa//Downloads//deepak_1.png")

Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Css that you should check :

input[type='file']

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the css and see, if your desired elementis getting **highlighted** with1/1` matching node.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38