0

Final task is to upload photos to site.

When i click on Upload photo - Window from Windows pops up and ask user to select pictures

I managed somehow to click on Upload and the window opens.

try:
    myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/main/div[2]/div/div/div[2]/section[1]/div/div[2]/div/label/div/div[1]/div/div'))) #.click(    
    myElem.click()
    myElem.SendKeys("path")
except TimeoutException:
    errorDuringFill = True

Also tried with pyWinAuto and pyAutoIt

Wasn't able to accomplish it.

Using:

webdriver.Firefox() 

Edit HTML:

<div class="listing-editor__box-content">
   <input id="img-file-input" type="file" multiple="multiple" accept=".png, .jpg, .jpeg" class="listing-editor__input-img-files" aria-required="true" aria-invalid="false">
   <div class="btn btn--large btn--wide bg--dark-gray">
      <div class="d--fl jc--c ai--c">
         <i class="l-icon cloud m--r--2"></i>
         <div class="tc--white">UPLOAD PHOTOS</div>
      </div>
   </div>
   <div class="tc--lg">or drag them in</div>
</div>
2
  • Please share HTML of upload button Commented Jan 23, 2020 at 14:14
  • @Muzzamil added Commented Jan 23, 2020 at 14:21

2 Answers 2

1

Try with below locator using ID instead absolute xpath

    myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.ID, 'img-file-input')))    
    myElem.send_keys("path")
Sign up to request clarification or add additional context in comments.

9 Comments

Muzzamil, one question more. Can i push multiple pictures like this ?
@ProgramerAnel Yes you can
By calling this method multiple times i see. I thought in send keys put bunch of paths
@ProgramerAnel ahhh i need to check it if some way with sendkey or JS
In java, it works like (“Path1 \n path2”). You can try in python with \n between path of files , if you want to check.
|
0

You need to send the file to the <input> tag using SendKeys. No need to use pywinauto. You can do it as follows:

try:
    myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/main/div[2]/div/div/div[2]/section[1]/div/div[2]/div/label/div/div[1]/div/div')))     
    myElem.click()
    driver.find_element_by_xpath('//input[@id='img-file-input']').SendKeys("filePath")
except TimeoutException:
    errorDuringFill = True

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.