1

I'm getting the error below when using "send_keys" for a choose file button in selenium in Python, using Chrome Driver:

webDriverException: Message: unknown error: cannot focus element

After some research, I tried to use the action chain method:

actions = ActionChains(self.driver)
actions.move_to_element(e)
actions.send_keys("C:\Users\devuser\Desktop\Untitled.png")
actions.perform()

This executes with no error, however, the file is not uploaded. Any idea how to solve this issue? Thanks.

Update: The html is below:

<div class="qq-upload-button" style="position: relative; overflow: hidden; direction: ltr;">Upload Image
   <input multiple="multiple" type="file" name="file" style="position: absolute; right: 0px; top: 0px; font-family: Arial; font-size: 118px; margin: 0px; padding: 0px; cursor: pointer; opacity: 0;">
</div>
JACK ZHANG
  • 600
  • 1
  • 7
  • 16
  • any specific reason to use `actions` class here ? directly `element.send_keys("C:\Users\devuser\Desktop\Untitled.png")` not working ? – NarendraR Jan 23 '17 at 04:22
  • I guess there is no html code like `` for the concerned 'upload file' button. So, [normal upload using sendkeys](http://stackoverflow.com/a/28206771/4193730) will not work. So, you might have to use something similar to [Robot class](http://sqa.stackexchange.com/a/15730/22560) (as in java), or Sikuli or AutoIt.. – Subh Jan 23 '17 at 06:52
  • @NarendraRajput ya it doesnt work, it throws the error in the description. – JACK ZHANG Jan 23 '17 at 19:08
  • @Subh updated the html code in the question. – JACK ZHANG Jan 23 '17 at 19:08
  • Thanks. So, which element are you sending the image path to ? The outer `div` or the `input` tag inside it? – Subh Jan 24 '17 at 07:06
  • @Subh the input – JACK ZHANG Feb 03 '17 at 22:43
  • This piece of code will help you out. [https://stackoverflow.com/a/11872608/4193730](https://stackoverflow.com/a/11872608/4193730) – Subh Jul 20 '17 at 06:49

0 Answers0