Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 unable to load file using python selenium
#1
Hi All,
I am trying to upload any dummy file from any arbitrary path but this is not working. I have removed driver.close() ,juts to check my file is uploaded or not .

Please change the path of file which you want to upload and I am opening generic site.


from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#Getting local session of Chrome
driver=webdriver.Chrome()

#put here the adress of your page
driver.get("https://files.fm/")
#put here the content you have put in Notepad, ie the XPath


	
#elem=driver.find_elements_by_xpath( '//*[@id="tsf"]/div[2]/div[3]/center/input[1]')############### this is one of name 
#elem.send_keys("google search through python")

'''for e in elem:
    e.send_keys("google search through python")'''
elem2=driver.find_element_by_id('file_upload').send_keys("C:\\Users\\pubhatia\\Documents\\learning\\python\\call_url.py")
print(elem2)
##driver.close()
Output:
DevTools listening on ws://127.0.0.1:12670/devtools/browser/9a8e734d-27a3-490f-ac0f-521545234943 None
Please confirm what is wrong in this code

Also can some one explain the meaning of this output
Quote
#2
My suspection here that your not find the "file_upload" element.

elem2=driver.find_element_by_id('file_upload')
print(elem2)
elem2.send_keys("C:\\Users\\pubhatia\\Documents\\learning\\python\\call_url.py")
Can you try this code? What does it print?
Quote
#3
Hi hashivaraj,

I tried what u have mentioned and as per my understanding it is working fine. Please correct me if I am wrong .

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#Getting local session of Chrome
driver=webdriver.Chrome()

#put here the adress of your page
driver.get("https://files.fm/")
#put here the content you have put in Notepad, ie the XPath


	
#elem=driver.find_elements_by_xpath( '//*[@id="tsf"]/div[2]/div[3]/center/input[1]')############### this is one of name 
#elem.send_keys("google search through python")

'''for e in elem:
    e.send_keys("google search through python")'''
#elem2=driver.find_element_by_id('file_upload').send_keys("C:\\Users\\pubhatia\\Documents\\learning\\python\\call_url.py")
#print(elem2)


elem2=driver.find_element_by_id('file_upload')
print(elem2)
elem2.send_keys("C:\\Users\\pubhatia\\Documents\\learning\\python\\call_url.py")
driver.close()


      
Output:
DevTools listening on ws://127.0.0.1:12834/devtools/browser/3cfbab60-fd17-4582-979f-5cc172054f54 <selenium.webdriver.remote.webelement.WebElement (session="498744c3b6f8c6219d4f6c85c11e66e2", element="0.4471727654327058-1")>
Quote
#4
Hi All,
Please help in resolving this issue.
Quote
#5
elem2=driver.find_element_by_id('file_upload')
print(elem2)
elem2.send_keys("C:\\Users\\pubhatia\\Documents\\learning\\python\\call_url.py")
Ok that looking good. This means that you did manage to find the element and then you did manage to upload path.
But you seem to close the webdriver. I would suggest that you seen send an "ENTER" key for upload the file path you want to upload

builder = Actions(driver);
builder.keyDown(Keys.ENTRE).perform()
I haven't tested the code. That was such and idea. Lookup the selenium doc.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Selenium cant get xpaths/load url draw134 2 171 Mar-30-2020, 11:24 AM
Last Post: draw134
  Scrapping javascript website with Selenium where pages randomly fail to load JuanJuan 14 959 Dec-27-2019, 12:32 PM
Last Post: JuanJuan
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 584 Aug-04-2019, 11:10 AM
Last Post: pjn4
  Selenium Parsing (unable to Parse page after loading) oneclick 6 1,137 Jan-13-2019, 03:10 AM
Last Post: oneclick
  Unable to gather data using beautifulscoup() [Output shows blank file] rishab123s 1 1,133 Apr-13-2018, 04:35 PM
Last Post: snippsat
  file upload from windows10 machine using send_key in selenium fails nithya_g 3 1,866 Jan-12-2018, 09:32 PM
Last Post: metulburr
  Unable to select iframe using selenium endejoli 1 1,163 Jan-11-2018, 05:13 PM
Last Post: j.crater
  Unable to load cookies with Pickle HiImNew 5 5,564 Jan-04-2018, 12:36 PM
Last Post: snippsat
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 1,297 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Issues running Selenium to download zip file davehughes87 4 3,148 Jan-12-2017, 02:19 PM
Last Post: metulburr

Forum Jump:


Users browsing this thread: 1 Guest(s)