I want to automate file compression on " http://pdfcompressor.com/ " website. I used selenium to upload files but failed to do so. Below is the code
file_path = "/home/gugli/Documents/script_py/Dainik_Jagron/h2.pdf"
browser = webdriver.Firefox()
url = 'http://pdfcompressor.com/'
browser.get(url)
I tried inserting in the input tag but got an err
browser.find_element_by_id('html5_1cciqvn90sehe7rachs1c3m03').send_keys(filepath)
this is the snapshot of input tag
following is the err :
Traceback (most recent call last):
File "/home/gugli/Documents/script_py/Dainik_Jagron/uploadfiles.py", line 32, in <module>
browser.find_element_by_id('html5_1cciqvn90sehe7rachs1c3m03').send_keys("/home/gugli/Documents/script_py/Dainik_Jagron/h2.pdf")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 330, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 832, in find_element
'value': value})['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException:
Message: Unable to locate element: [id="html5_1cciqvn90sehe7rachs1c3m03"]
The file is stored in a "ul" tag. But failed to upload in this tag even. Here is the snapshot of dom structure for before and after uploading the file
The file uploaded is stored as a "li" element ( image 3 ). I tried inserting in "div id = carousel" container but again it was a failed attempt. How else can I upload file here using python.
-
Possible duplicate of Selenium "selenium.common.exceptions.NoSuchElementException" when using Chromeundetected Selenium– undetected Selenium2018年05月03日 12:51:29 +00:00Commented May 3, 2018 at 12:51
1 Answer 1
From your url it seems the element not found by the selenium
selenium.common.exceptions.NoSuchElementException:
Message: Unable to locate element: [id="html5_1cciqvn90sehe7rachs1c3m03"]
In this specific case the id of input field is auto generated, it means it will be different for every session. What you see as an id is different than when you open through selenium.
I would suggest to locate the element by XPath not by id in this particular case
Use XPath .//input[type = 'file']
or something other so that selenium can identify the element
Explore related questions
See similar questions with these tags.