3

I'm trying to upload a file and proceed further with my testing but the issue here is that the solution proposed by many on this site doesn't seem to work for me.

Given below is the window.

enter image description here

I'm now trying to provide a path directly instead of clicking the file input (which by the way, was the solution provided on several stackoverflow pages) on the following page.

https://huew.co/discover/

newip = chrome_browser.find_element_by_xpath("/html/body/div[4]/div/div[1]/form/input")
newip.send_keys("D:\p1.png")

It doesn't seem to pass the path D:\p1.png Can someone please help me with this ?

I do not want to use AutoIt, I'd like to achieve this file upload by making use of selenium and python. I believe it should be possible but I'm having a hard time achieving it. I've even tried using ActionChains but that didn't resolve the issue either.

My OS is Windows 10, browse is Google Chrome (Version 71.0.3578.98)

1 Answer 1

1

for the error File not found you need to escape the backslash \ with \\ or using slash / and if you get error cannot locate the element add wait using WebDriverWait but I didn't get this error.

from selenium.webdriver.support.ui import WebDriverWait

# wait max 10 seconds
newip = WebDriverWait(chrome_browser, 10).until(
    lambda chrome_browser: chrome_browser.find_element_by_xpath("/html/body/div[4]/div/div[1]/form/input")
)
newip.send_keys("D:\\p1.png")

# click the Submit using javascript
driver.execute_script('''
   document.querySelector('button.desktop-photo-submit.ng-scope').click()
''')
Sign up to request clarification or add additional context in comments.

4 Comments

The snippet of code you've pasted in your answer is working i.e. it's able to upload the file located at D:\\p1.png (or really any location for that matter) ?
location is matter, the file must exist.
Yes the file does exist on my setup but it still doesn't lead to the file being selected for upload and the "SUBMIT" button becoming visible. Does the fact that control is handed over to the native OS window affect Selenium ? I've heard this is a real possibility.
the element #preloader overlapped the button and prevent selenium to click it. edited the answer, take a look.

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.