Reputation: 2207
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.
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.
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)
Upvotes: 3
Views: 6268
Reputation: 19154
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()
''')
Upvotes: 1