java - How to handle windows file upload using Selenium WebDriver? -


i have seen lots of questions , solutions on file upload using selenium webdriver on stackoverflow. none of working following scenario.

someone has given solution following

// assuming driver healthy webdriver instance webelement fileinput = driver.findelement(by.name("uploadfile")); fileinput.sendkeys("c:/path/to/file.jpg"); 

but still can't find window handle how can work on that??

screenshot

i looking solution above scenario

please check of following website

http://www.uploadify.com/demos/ http://www.zamzar.com/ 

// assuming driver healthy webdriver instance webelement fileinput = driver.findelement(by.name("uploadfile")); fileinput.sendkeys("c:/path/to/file.jpg"); 

hey, that's mine somewhere :).


in case of zamzar web, should work perfectly. don't click element. type path it. concrete, should absolutely ok:

driver.findelement(by.id("inputfile")).sendkeys("c:/path/to/file.jpg"); 

in case of uploadify web, you're in pickle, since upload thing no input, flash object. there's no api webdriver allow work browser dialogs (or flash objects).

so after click flash element, there'll window popping you'll have no control over. in browsers , operating systems know, can pretty assume after window has been opened, cursor in file name input. please, make sure assumption true in case, too.

if not, try jump pressing alt + n, @ least on windows...

if yes, can "blindly" type path using robot class. in case, in way of:

driver.findelement(by.id("swfupload_0")).click(); robot r = new robot(); r.keypress(keyevent.vk_c);        // c r.keyrelease(keyevent.vk_c); r.keypress(keyevent.vk_colon);    // : (colon) r.keyrelease(keyevent.vk_colon); r.keypress(keyevent.vk_slash);    // / (slash) r.keyrelease(keyevent.vk_slash); // etc. whole file path  r.keypress(keyevent.vk_enter);    // confirm pressing enter in end r.keyrelease(keyevent.vk_enter); 

it sucks, should work. note might need these: how can make robot type `:`? , convert string keyevents (plus there new , shiny keyevent#getextendedkeycodeforchar() similar work, available jdk7).


for flash, alternative know (from this discussion) use dark technique:

first, modify source code of flash application, exposing internal methods using actionscript's externalinterface api. once exposed, these methods callable javascript in browser.

second, javascript can call internal methods in flash app, use webdriver make javascript call in web page, call flash app.

this technique explained further in docs of flash-selenium project. (http://code.google.com/p/flash-selenium/), idea behind technique applies webdriver.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -