unable to load file using python selenium - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: unable to load file using python selenium (/thread-6757.html) |
unable to load file using python selenium - purnima1 - Dec-06-2017 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() Please confirm what is wrong in this code Also can some one explain the meaning of this output RE: unable to load file using python selenium - hshivaraj - Dec-06-2017 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? RE: unable to load file using python selenium - purnima1 - Dec-07-2017 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()
RE: unable to load file using python selenium - purnima1 - Dec-12-2017 Hi All, Please help in resolving this issue. RE: unable to load file using python selenium - hshivaraj - Dec-12-2017 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. |