2

ScreenshotI am trying to upload a file on maketime.io using selenium in python.

attach = driver.find_element_by_id('part_input_3d_10262')
attach.send_keys("filepath")

The file has to be uploaded in the following element.

<input ng-show="false" id="part_input_3d_10262" name="part_input_3d" accept=".dxf,.step,.stp" ng-class="{ 'has-file': part.asset3d }" nv-file-select="" uploader="uploader3d" class="ng-hide" type="file">

When i run the code, it gives :

ElementNotInteractableException: Element <> is not reachable by keyboard. 

I have tried introducing wait to ensure that the page completely loads before "attach.send_keys" is run.

Looks like this element is hidden which makes it non-reachable. I am not able to figure out how to fix this. I have looked at other posts with similar issues but still could not fix it.

JJJ
  • 32,902
  • 20
  • 89
  • 102
deep
  • 29
  • 1
  • 5
  • Is the element visible on the webpage? You can't send keys to something that is not visible. – sytech Mar 28 '18 at 17:44
  • What is visible on the webpage is the "attach model" button. I have added a screen shot of the webpage in the post. You need to click on the "attach model" on the webpage to upload the part. The element for that is the one highlighted with the span tag. Sorry, i don't know Java script or HTML. So i am not sure if i have correctly answered your question. – deep Mar 28 '18 at 19:05
  • Possible duplicate of [How to click on across browsers using Selenium Webdriver?](https://stackoverflow.com/questions/9726005/how-to-click-on-input-type-file-across-browsers-using-selenium-webdriver) – SiKing Mar 28 '18 at 19:51
  • 1
    Possible duplicate of [How to resolve ElementNotInteractableException in Selenium webdriver?](https://stackoverflow.com/questions/43868009/how-to-resolve-elementnotinteractableexception-in-selenium-webdriver) – undetected Selenium Mar 28 '18 at 19:54

2 Answers2

2

use javascript to make the element visible first

driver.execute_script('''
document.getElementById('part_input_3d_10262'‌​).className="ng-show"; 
''')

or try this

driver.execute_script('''
document.getElementById('part_input_3d_10262'‌​).setAttribute("ng-show", "true"); 
''')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Addison Joseph
  • 126
  • 2
  • 15
  • Thanks Joseph. It still gives the same error "ElementNotInteractableException: Element is not reachable by keyboard" – deep Mar 28 '18 at 23:19
0

The error says it all :

ElementNotInteractableException: Element <> is not reachable by keyboard. 

As per the HTML you have shared the element is a Angular Element. So first of all you have to induce WebDriverWait for the element to be clickable and then remove the attribute class set as ng-hide and also change the attribute ng-show to true as follows :

attach = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='ng-hide' and starts-with(@id,'part_input_3d_') and @name='part_input_3d']")))
driver.execute_script("arguments[0].removeAttribute('class')", element)
driver.execute_script("arguments[0].setAttribute('ng-show','true')", element)
attach.send_keys("filepath")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352