4

I read a lot about and everyone advice to don't use the Windows Upload and write directly the path of my file; I even try to use some command found in the forum like:

swicthTo()
switch_to_window()
window_handles

but I didn't find any solution yet. My main problem is that time I have no space to send directly the path of my file (see image below, the space to introduce the path is grey-out) but I have only the option to click in "Browse" and open the Windows Uploader:

enter image description here

Do you know how can I switch to the upload window's Windows and introduce my fie?

I try even in this way:

browse=wait(".//*[@id='fileinput']") #open the window upload
browse.click()
time.sleep(1)


def handle_dialog(element_initiating_dialog, dialog_text_input):
    upload_dialog = driver.switch_to_active_element
    print (upload_dialog)
    upload_dialog.send_keys(dialog_text_input)
    upload_dialog.send_keys(selenium.webdriver.common.keys.Keys.ENTER) # the ENTER key closes the upload dialog, other thread exits

handle_dialog(browse, "foobar.txt")

I find the windows and when I print I have this object:

We are already in the Location->Details Page <bound method WebDriver.switch_to_active_element of <selenium.webdriver.ie.webdriver.WebDriver (session="3e725bb7-40a7-452a-ad90-9cca1d41296a")>>

But after when I try to do send_keys I receive this error:

Traceback (most recent call last): File "C:\Users\carlo.agresta\Desktop\IE - iQsonar.py", line 149, in handle_dialog(browse, "foobar.txt") File "C:\Users\carlo.agresta\Desktop\IE - iQsonar.py", line 145, in handle_dialog upload_dialog.send_keys(dialog_text_input) AttributeError: 'function' object has no attribute 'send_keys'

I partially found a solution, I let behave my code as if the window upload is an alert so I do in this way:

browse=wait(".//*[@id='fileinput']")
browse.click()
time.sleep(1)

upload_dialog = driver.switch_to_alert()
print (upload_dialog)

upload_dialog.send_keys("C:\\Users\\carlo.agresta\\Desktop\\V4LabCredentials.csv")

Now my problem is that I can't accept accept and close the window :S any advice?

Thanks so much in advance

7
  • 1
    You should not open the dialog at all. Because then it goes to the native OS window which Selenium cannot control. What you should do is change browse.click() to browse.send_keys("<complete file path">) Commented Sep 27, 2017 at 16:13
  • Yes I know but I don't have other option, the text box is grey out and I don't have any other way to select my file. So far I could open the dialog window and introduce my path, I'm getting crazy how to accept it because the command .accept() is not working and there are just 2 bottom "open" and "Cancel". other option to solve my issue? any advice? Commented Sep 27, 2017 at 16:21
  • manually when i arrive at this point, pressing ENTER I accept the windows/pop-up, so I try to let my script press the key ENTER but it's not working neither because it replace my path with a dot "." :S Commented Sep 27, 2017 at 16:27
  • Even if it is greyed, have you tried using send_keys ? Commented Sep 27, 2017 at 17:35
  • Yes I try, it's not working I can't really do anything there :S Commented Sep 28, 2017 at 8:04

1 Answer 1

9

use autoit example code:

import autoit
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys

ActionChains(driver).move_to_element( driver.find_element_by_xpath("//div[@class='upload_button']")).click().perform()
handle = "[CLASS:#32770; TITLE:Open]"
autoit.win_wait(handle, 60)
autoit.control_set_text(handle, "Edit1", "\\file\\path")
autoit.control_click(handle, "Button1")
Sign up to request clarification or add additional context in comments.

Comments

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.