简体   繁体   中英

Accessing a File Upload Window - Python + Selenium

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.

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)

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()
''')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM