samedi 18 juin 2016

Python uploading image/file with selenium webdriver

The folowing is a snip of some crowdfire.com HTML code, where im trying to upload a file in the input class =...

<div id="ember1089" class="ember-view">
    <div id="ember1090" class="action__addImage pointer ember-view tooltipstered"> 
         <div data-ember-action="1091">
                <img class="iconImg iconImg--camera" src="/publish/images/icon-camera-b432ac4c5b369d4616baf097b951d9b4.png"/>
                <span>Add an image</span>
         </div>
<input class="js-file-input action__fileInput" type="file" data-ember-action="1092"/>
</div>

Now below is what i have so far. I have created driver instance, the code before logs in the website without a problem and locates all other xpaths

image = driver.find_element_by_xpath('.//*[@id='ember1089']/input')
time.sleep(2)
print 'found element'
image.send_keys('C:UsersBrianDesktopEmpire_fortBotsGetPICturesEmpire.jpg)
print 'uploading'
time.sleep(5)

the following is the error i get, and i really don't understand what is the problem,On the website there is an "add an image" link. if clicked it brings up window's explorer from where the user can select a file and upload it.

waiting
about toupload
found element
Traceback (most recent call last):
  File "C:UsersBrianDesktopEmpire_fortBotsGetPICturesnowupload.py", line 55, in <module>
    image.send_keys(r'C:UsersBrianDesktopEmpire_fortBotsGetPICturesEmpire.jpg')
  File "C:Python2.7.11libsite-packagesseleniumwebdriverremotewebelement.py", line 321, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
  File "C:Python2.7.11libsite-packagesseleniumwebdriverremotewebelement.py", line 456, in _execute
    return self._parent.execute(command, params)
  File "C:Python2.7.11libsite-packagesseleniumwebdriverremotewebdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:Python2.7.11libsite-packagesseleniumwebdriverremoteerrorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
    at fxdriver.preconditions.visible (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver@googlecode.com/components/command-processor.js:10092)
    at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver@googlecode.com/components/command-processor.js:12644)
    at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.prototype.execute/< (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)

Thanks!

Aucun commentaire:

Enregistrer un commentaire