selenium icon indicating copy to clipboard operation
selenium copied to clipboard

Sending keys to an Internet Explorer 9 / 10 / 11 file upload form causes the OS file browser window to open

Open ghost opened this issue 11 years ago • 16 comments

Sending keys to an Internet Explorer 9 / 10 / 11 file upload form causes the OS file browser window to open.

Python bindings Selenium 2.46.0, 2.48.0 IEDriverServer_Win32_2.46.0, IEDriverServer_Win32_2.48.0 Windows 10, Windows 7 and Windows 2012

Test example as follows;

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

  <form id="installform" method="post" action="query" enctype="multipart/form-data">
        <input id="npkchooser" name="software" type="file">
  </form>

</body>
</html>
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Ie()
driver.get("http://jsbin.com/cunodo")
WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.ID, "npkchooser")))
driver.find_element_by_id("npkchooser").send_keys("c:\\test_file.txt")

Please let me know what further information you require.

ghost avatar Nov 16 '15 14:11 ghost

ie.txt

Adding IE11 trace logs.

ghost avatar Nov 16 '15 15:11 ghost

I'm experiencing the same problem. Windows File explorer opens which blocks IE.

Selenium Webdriver version - 2.48.1 IE 11,Windows 10 and IE 7, Windows XP

Looks like a known issue. https://code.google.com/p/selenium/issues/detail?id=3858

nidhimj22 avatar Nov 18 '15 06:11 nidhimj22

@matthew-horrocks Is there any chance the file you are attempting to upload does not exist? The symptoms you describe are consistent with that behavior. None of the file upload tests in the Selenium project's test suite are failing in any of our CI runs.

jimevans avatar Nov 18 '15 11:11 jimevans

I'm also having the same problems:

On: IE10/IE11 on Windows 7 x64 Using: Selenium 2.48.0 with IEDriverX86 2.48.0

JurgenR avatar Nov 24 '15 15:11 JurgenR

Same question applies to @JurgenR and @nidhimj22. Is there any chance the file you're attempting to upload does not exist in the location you're specifying?

jimevans avatar Nov 24 '15 15:11 jimevans

No, I am 100% certain the path exists because the same code runs fine on Firefox and Chrome. It started occurring after upgrading Selenium to 2.48

JurgenR avatar Nov 24 '15 16:11 JurgenR

@JurgenR Then I'm going to need to insist on you providing a full reproducible test case. The case supplied by @matthew-horrocks works without issue in my environment (IE 11 on 64-bit Windows 10). Furthermore, I'm quite sure the file upload code didn't change between 2.46 and 2.48.

Also, be aware that the IE driver requires the full, absolute path to the file being uploaded; relative paths (which may work with Chrome and/or Firefox) will not work at all.

jimevans avatar Nov 24 '15 16:11 jimevans

Please have a look at https://code.google.com/p/selenium/issues/detail?id=3858#c16 . My code is also running on a slow machine. Can you consider looking at this?

JurgenR avatar Nov 24 '15 17:11 JurgenR

@jimevans My code runs on IE 11, Win 8.1 but fails on IE 11, Win 10. It works on all other IE's. I have attached a Ruby code snippet.

driver.file_detector = lambda do |args| str = args.first.to_s str if File.exist?(str) end driver.navigate.to "http://www.fileconvoy.com" element = driver.find_element(:id, "upfile_0") driver.execute_script("document.getElementById('upfile_0').setAttribute('value','C:\Users\hello\Desktop\audio\first_noel.mp3')") element.send_keys("C:\Users\hello\Desktop\audio\first_noel.mp3"); driver.find_element(:id, "readTermsOfUse").click; driver.find_element(:name, "form_upload").submit; driver.quit

nidhimj22 avatar Nov 24 '15 17:11 nidhimj22

I'm not convinced the "slow machine" excuse is the cause. This should be the case very, very, very rarely. The initial issue reporter's log shows the "No dialog directly owned by the top-level window" message, but there is no follow-on message that indicates the dialog was properly closed.

Nevertheless, I've just completed adding a capability to the IE driver, ie.fileUploadDialogTimeout, with which you can customize the amount of time (in milliseconds) that the driver waits for the file dialog to appear before giving up looking for it. It defaults to 1000 milliseconds.

Additionally, sendKeys will now throw an exception if the file you're attempting to upload does not exist. This will prevent the case where the dialog stays open because the user has passed in a file name that does not exist.

If you want to try out these changes, you can download the latest private prebuilt IE driver here. It will be version number 2.48.0.3. If you can use this version, and publish the log file, that might shed some further light on what might be causing the problem.

jimevans avatar Nov 24 '15 19:11 jimevans

Hello @jimevans , I will try this build today testing with ie.fileUploadDialogTimeout=3000 and will let you know if this helps.

Thank you!

JurgenR avatar Nov 25 '15 08:11 JurgenR

@jimevans , this parameter works like a charm

JurgenR avatar Nov 27 '15 11:11 JurgenR

@jimevans I had a similiar problem. And this parameter works for me. Do you want some logs?

godlark avatar Dec 07 '15 12:12 godlark

Unless someone has a case where using the timeout a parameter still fails, I'm content to close the issue.

jimevans avatar Dec 07 '15 12:12 jimevans

@jimevans Sorry, I was too fast with making a reply. Sometimes it doesn't work Logs:

server.cc(281) Command: POST /session/8d834df8-db33-432d-bfd2-04f3d0d34ec9/element/b32dcad5-e785-4320-8368-2473c1ff0e8b/elements {"using": "css selector", "sessionId": "8d834df8-db33-432d-bfd2-04f3d0d34ec9", "id": "b32dcad5-e785-4320-8368-2473c1ff0e8b", "value": "input.btn-chooseFile"}\r\nD 2015-12-07 05:31:31:153 command.cc(36) Raw JSON command: { "name" : "findChildElements", "locator" : { "sessionid" : "8d834df8-db33-432d-bfd2-04f3d0d34ec9", "id" : "b32dcad5-e785-4320-8368-2473c1ff0e8b" }, "parameters" : {"using": "css selector", "sessionId": "8d834df8-db33-432d-bfd2-04f3d0d34ec9", "id": "b32dcad5-e785-4320-8368-2473c1ff0e8b", "value": "input.btn-chooseFile"} }\r\nD 2015-12-07 05:31:31:154 IECommandExecutor.cpp(563) No alert handle is found\r\nI 2015-12-07 05:31:31:166 Browser.cpp(124) No child frame focus. Focus is on top-level frame\r\nI 2015-12-07 05:31:31:192 Browser.cpp(124) No child frame focus. Focus is on top-level frame\r\nD 2015-12-07 05:31:31:238 ElementFinder.cpp(123) Using FindElements atom to locate element having css = input.btn-chooseFile\r\nI 2015-12-07 05:31:31:238 Browser.cpp(124) No child frame focus. Focus is on top-level frame\r\nD 2015-12-07 05:31:31:312 VariantUtilities.cpp(82) Result type is DispStaticNodeList\r\nD 2015-12-07 05:31:31:314 VariantUtilities.cpp(82) Result type is DispStaticNodeList\r\nI 2015-12-07 05:31:31:320 VariantUtilities.cpp(179) Unknown type of dispatch is found in result, assuming IHTMLElement\r\nD 2015-12-07 05:31:31:322 ElementRepository.cpp(66) Element is not yet managed\r\nD 2015-12-07 05:31:31:333 server.cc(355) Response: {"sessionId":"8d834df8-db33-432d-bfd2-04f3d0d34ec9","status":0,"value":[{"ELEMENT":"5b903227-9e29-4608-87a4-53615e085c59","element-6066-11e4-a52e-4f735466cecf":"5b903227-9e29-4608-87a4-53615e085c59"}]}\r\n\r\nD 2015-12-07 05:31:31:339 server.cc(281) Command: GET /session/8d834df8-db33-432d-bfd2-04f3d0d34ec9/element/5b903227-9e29-4608-87a4-53615e085c59/displayed {}\r\nD 2015-12-07 05:31:31:339 command.cc(36) Raw JSON command: { "name" : "isDisplayed", "locator" : { "sessionid" : "8d834df8-db33-432d-bfd2-04f3d0d34ec9", "id" : "5b903227-9e29-4608-87a4-53615e085c59" }, "parameters" : {} }\r\nD 2015-12-07 05:31:31:339 IECommandExecutor.cpp(563) No alert handle is found\r\nI 2015-12-07 05:31:31:349 Browser.cpp(124) No child frame focus. Focus is on top-level frame\r\nD 2015-12-07 05:31:31:439 server.cc(355) Response: {"sessionId":"8d834df8-db33-432d-bfd2-04f3d0d34ec9","status":0,"value":true}\r\n\r\nD 2015-12-07 05:31:31:445 server.cc(281) Command: POST /session/8d834df8-db33-432d-bfd2-04f3d0d34ec9/element/5b903227-9e29-4608-87a4-53615e085c59/value {"sessionId": "8d834df8-db33-432d-bfd2-04f3d0d34ec9", "id": "5b903227-9e29-4608-87a4-53615e085c59", "value": ["C", ":", "\\\\", "j", "e", "n", "k", "i", "n", "s", "\\\\", "w", "o", "r", "k", "s", "p", "a", "c", "e", "\\\\", "B", "M", ".", "c", "2", "_", "f", "d", "s", "w", "_", "f", "r", "o", "n", "t", "e", "n", "d", "_", "d", "e", "v", "e", "l", "o", "p", "m", "e", "n", "t", ".", "R", "E", "S", "C", "U", "E", "_", "C", "O", "N", "S", "O", "L", "E", "_", "S", "C", "T", "\\\\", "r", "e", "s", "c", "u", "e", "_", "c", "o", "n", "s", "o", "l", "e", "\\\\", "d", "a", "t", "a", "\\\\", "f", "r", "o", "n", "t", "e", "n", "d", "\\\\", "D", "u", "m", "m", "y", "P", "a", "c", "k", "a", "g", "e", ".", "z", "i", "p"]}\r\nD 2015-12-07 05:31:31:445 command.cc(36) Raw JSON command: { "name" : "sendKeys", "locator" : { "sessionid" : "8d834df8-db33-432d-bfd2-04f3d0d34ec9", "id" : "5b903227-9e29-4608-87a4-53615e085c59" }, "parameters" : {"sessionId": "8d834df8-db33-432d-bfd2-04f3d0d34ec9", "id": "5b903227-9e29-4608-87a4-53615e085c59", "value": ["C", ":", "\\\\", "j", "e", "n", "k", "i", "n", "s", "\\\\", "w", "o", "r", "k", "s", "p", "a", "c", "e", "\\\\", "B", "M", ".", "c", "2", "_", "f", "d", "s", "w", "_", "f", "r", "o", "n", "t", "e", "n", "d", "_", "d", "e", "v", "e", "l", "o", "p", "m", "e", "n", "t", ".", "R", "E", "S", "C", "U", "E", "_", "C", "O", "N", "S", "O", "L", "E", "_", "S", "C", "T", "\\\\", "r", "e", "s", "c", "u", "e", "_", "c", "o", "n", "s", "o", "l", "e", "\\\\", "d", "a", "t", "a", "\\\\", "f", "r", "o", "n", "t", "e", "n", "d", "\\\\", "D", "u", "m", "m", "y", "P", "a", "c", "k", "a", "g", "e", ".", "z", "i", "p"]} }\r\nD 2015-12-07 05:31:31:446 IECommandExecutor.cpp(563) No alert handle is found\r\nI 2015-12-07 05:31:31:452 Browser.cpp(124) No child frame focus. Focus is on top-level frame\r\nD 2015-12-07 05:31:31:474 Element.cpp(485) Element is a block element, using IHTMLElement2::getBoundingClientRect\r\nD 2015-12-07 05:31:31:502 Element.cpp(562) Element is not in a frame\r\nD 2015-12-07 05:31:31:564 Script.cpp(439) Result type is string\r\nD 2015-12-07 05:31:31:565 Element.cpp(354) (x, y, w, h): 567, 226, 264, 24\r\nD 2015-12-07 05:31:31:572 c:\\projects\\webdriver\\cpp\\iedriver\\CommandHandlers/SendKeysCommandHandler.h(145) Clicking upload button and starting to handle file selection dialog\r\nW 2015-12-07 05:31:32:577 c:\\projects\\webdriver\\cpp\\iedriver\\CommandHandlers/SendKeysCommandHandler.h(204) No dialog directly owned by the top-level window\r\nW 2015-12-07 05:31:34:477 c:\\projects\\webdriver\\cpp\\iedriver\\CommandHandlers/SendKeysCommandHandler.h(308) No edit found\r\n'

godlark avatar Dec 07 '15 14:12 godlark

I am also experiencing the same problem like matthew-horrocks.

sello4354 avatar Oct 20 '17 21:10 sello4354