0

I need to upload a file using 'upload' button. after that a window will appear but I can't find the exact ID from HTML code. here is the screen shots and my code: enter image description here

enter image description here

`time.sleep(1) element=driver.find_element_by_id("Upload-Action-Ico").click()

driver.find_element_by_xpath("//*[contains(text(), 'File')]").send_keys("file path")`

4 Answers4

0

I think that the ID is 'file' so I think this should work

time.sleep(1) 
element=driver.find_element_by_id("file").click()
Oliver Hnat
  • 797
  • 4
  • 19
0

Try click on it and show the HTML code. There is a word "Button" or similar. Can you share me the url of the site? I hope I can help you and excuse me for my english. (It isn't my mother-language)

Persona
  • 63
  • 9
0

The input field does not contain any text. And its id is explicitly mentioned in the html, so you can try find_element_by_id:

driver.find_element_by_id("file").send_keys("file path")

If this doesn't work for you, then you can try using the xpath:

driver.find_element_by_xpath("//*[@id='file']").send_keys("file path")
Sushil
  • 5,440
  • 1
  • 8
  • 26
  • There is no such button in the html that u have provided. Are u sure that the html is right? – Sushil Nov 01 '20 at 11:34
0

You can use this code to select files, and after that, you should click on the upload button.

filePath = os.getcwd()+'\img.jpg'
driver.find_element_by_id('Upload-Action-Ico').send_keys(filePath)

os.getcwd() : returns the current working directory. img.jpg is located right next to the running script in the same directory.

Morteza Asadi
  • 414
  • 3
  • 13
  • selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable – Aref Farzaneh Nov 01 '20 at 12:01
  • 2
    A possibility is that the element is currently unclickable because it is not visible. I tested this code, and works perfectly. – Morteza Asadi Nov 01 '20 at 17:12
  • for more information, you can read this post: https://stackoverflow.com/questions/44119081/how-do-you-fix-the-element-not-interactable-exception – Morteza Asadi Nov 01 '20 at 17:19