1
<img src="images/file_explorer.png" class="browse" style="cursor: pointer;height:33px;" title="file from your computer">
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.keys import Keys

import time

driver = webdriver.Chrome(executable_path="C:/webdrivers/chromedriver.exe")
driver.maximize_window()
driver.get("https://www.collabera.com/find-a-job/search-jobs/?sort_by=dateposted&Posteddays=4000&searchany=QA&anylocation=usa")
time.sleep(3)
driver.find_element_by_css_selector("#srchpgbnnr > div:nth-child(1) > div:nth-child(1) > div > a").click()

driver.find_element_by_css_selector("body > section:nth-child(7) > div:nth-child(2) > div > div.col-md-offset-2.col-md-3.__jobdesc-sidebar.col-xs-hide > div > a").click()
time.sleep(15)
driver.find_element_by_css_selector("img.browse[src='images/file_explorer.png'][title='file from yourcomputer']").send_keys("C:\\Users\\user\\Desktop\\collebra.txt")

url:https://www.collabera.com/find-a-job/search-jobs/job-details/126013-qa-analyst-jobs-ann-arbor-mi

my code is above one its not working how to find element in above upload button code

3
  • Are you sure you want to invoke send_keys() on a <img> tag? Commented Apr 30, 2018 at 20:52
  • can u edit errors in that above code please? Commented Apr 30, 2018 at 21:35
  • It looks like you are trying to click on an element in a iframe. Can you try to switch to iframe first and then click on upload icon? Also windows file upload wizard is something you cannot handle with selenium (using send_keys()). You could windows shell scripting or python libraries (for example PyAutoIt) to handle the file upload. Commented May 1, 2018 at 5:01

2 Answers 2

1
  1. To be able to handle file upload form you need to switch to iframe:

    driver.switch_to.frame(driver.find_element_by_class_name("apply-form"))
    
  2. You need to handle input element, but not img:

    driver.find_element_by_xpath("//input[@type='file']").send_keys("C:\\Users\\user\\Desktop\\collebra.txt")
    
Sign up to request clarification or add additional context in comments.

6 Comments

no such element: Unable to locate element: {"method":"xpath","selector":"//input[@type='file']"}
On which line? Did you use time.sleep() before that line?
thank you very much i am struggling for 3 days its worked
Great. But note that while it works with time.sleep() using time.sleep() is a bad practice, you should try explicit/implicit waits
can u do me a favour how can i paste email and name next one in url :collabera.com/find-a-job/search-jobs/job-details/…
|
0

To find the element and invoke send_keys() method you can discard the time.sleep(5) and induce WebDriverWait and use any of the following options :

  • CSS_SELECTOR :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "img.browse[src='images/file_explorer.png'][title='file from your computer']"))).send_keys("C:\\Users\\user\\Desktop\\collebra.txt")
    
  • XPATH :

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@class='browse' and @src='images/file_explorer.png' and @title='file from your computer']"))).send_keys("C:\\Users\\user\\Desktop\\collebra.txt")
    

1 Comment

not working doesn't throws any light on whats wrong happening, update the question with your current code trial and error trace logs.

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.