1

I want to upload an image to a website using Selenium.

The HTML of the button which I have to click is in the image(Highlighted) below

Upload Button Element

The problem is when I click on that element a windows popup comes on the screen to select the image I want to upload, which I cannot control with Selenium. LIKE THIS

Please tell me How to Select the image from that popup and also tried the send_keys method but it was unsuccessful for me.

2 Answers2

0
  1. You need to install AutoIt "pip install -U pyautoit" through the cmd screen

  2. type "import autoit" on your script page

  3. Type the following before the file dialog pops up in your script:

    autoit.win_active("Open") autoit.control_send("Open","Edit1",r"Path with filename") autoit.control_send("Open","Edit1","{ENTER}")

For you reference https://pypi.python.org/pypi/PyAutoIt/0.3

Please Note : Section 3 will be implemented after click on the button. Hope this help you.

KunduK
  • 32,888
  • 5
  • 17
  • 41
0

From this quesion, read:

Upload input control opens a native dialog (it is done by browser) so clicking on the control or browse button via Selenium will just pop the dialog and the test will hang.

So, the solution from here:

file_input = driver.find_element_by_id("uploadBtn")
file_input.send_keys("/absolute/path/to/file")
abdullah.cu
  • 674
  • 6
  • 11