_[email protected] commented:_
Which version of PhantomJS are you using? Tip: run 'phantomjs --version'.
1.8.1
What steps will reproduce the problem?
I'll need some help / time to write a test. We are using this file upload component: http://blueimp.github.com/jQuery-File-Upload/
What is the expected output? What do you see instead?
Which operating system are you using?
Ubuntu 12.10 64 bit
Did you use binary PhantomJS or did you compile it from source?
binary
Please provide any additional information below.
I'm not sure if this is a case of https://code.google.com/p/phantomjs/issues/detail?id=941 or not. In this case the file really exists but phantomjs still crashes. I can retry once master has been updated with the pull request https://github.com/ariya/phantomjs/pull/390 to see if that helps. Meanwhile I'll try to code a test to the file upload demo page.
Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #993.
:star2: 3 people had starred this issue at the time of migration.
_[email protected] commented:_
We are having a similar issue with file uploads using valums/file-uploader (https://github.com/valums/file-uploader) seeming to occasionally produce crashes. I've tried running both the 1.8.1 binary for mac, linux x64, and the latest, locally-compiled phantomjs with updated ghostdriver on both platforms. It's a hard phantom crash, not a ghostdriver exception. Stack trace: https://gist.github.com/sj26/c500107cd5e2b30acef8
I suspect this is because both jquery fileuploader and valums fileuploader both remove and recreate the file input when attaching files and that phantomjs may be attemping to use the removed file input in event handlers et al. This should be fairly easy to guard against.
_[email protected] commented:_
If this is really like issue 941, a good way to verify it is to try it again with version 1.8.2 (contains the backported fix).
I've run into this same issue. Currently running 1.8.1, but can confirm that it's not an issue of a non-existing filepath. The same code executes successfully via selenium/firefox
are there any work-arounds while this bug gets resolved?
I started looking into a solution for this, and it seems to be a ghostdriver issue (not phantomjs). Or at least the upload timing out is happening in the ghostdriver code.
In the _postValueCommand() method in src/request_handlers/webelement_request_handler.js.
There's a check to "Detect if it's an Input File type", which seems to trigger the onFilePicker event. The callback never seems to execute (maybe because the element doesn't match the file input element - I don't know, still trying to figure out the solution).
Can confirm this is still an issue on windows
Sendkeys to file input method. phantom hangs forever (promise never resolves/rejects in webdriverjs, in my case)
Tidbits worth noting:
using node 11.13
using Protractor (wrapper around WebdriverJS)
using windows7
using phantomJS 1.9.7
using selenium 2.40.0
unfortunately we have also this issue.
phatnom js 1.9.2
driverversion 1.0.4
windows 8
i'm happy to provide any data if needed!
Here is the workaround I used with Selenium + Java bindings:
((PhantomJSDriver)driver).executePhantomJS("var page = this; page.uploadFile('input[type=file]', '/path/to/file');");
where my previous code was:
driver.findElement(By.xpath("//input[type='file']")).sendKeys("path/to/file");
com.github.detro:phantomjsdriver:1.2.0
phantomjs-1.9.7-linux-x86_64
I am having the same issue.
Windows 7
Python 3.4.1, selenium 2.42.1
PhantomJS 1.9.7
Same code works fine with firefox.
Any updates on this? I'm seeing the same thing. Thanks!
Uploading a file is working for me as long as the field doesn't allow multiple files.
This is an issue that needs to be resolved in GhostDriver: https://github.com/detro/ghostdriver/issues/282
Uploading a file to an input field with multiple works in CasperJS, but not with Selenium and GhostDriver.
I am trying this code:
((PhantomJSDriver) wd)
.executePhantomJS("var page = this;"+
"page.content='';"
+"page.uploadFile('#rtmedia_simple_file_input', 'E:\test.jpg');");
For single file only but its not working for me?
@juhi123 As far as I can see from the above code, the "\" [forward slash] is unescaped. Tried with the escaped one "\" locally and it hangs again. Then tried with the "/" slash and it works like a charm.
Haven't tried yet to escape it twice like "\" [I think it will work].
Hope it helps
I can confirm this bug. The call to sendKeys never returns, at least in the amount of time I have bothered to wait.
The workaround I found was to use javascript to change the form input from multiple = true to false.
This is working for me but I can only test cases involving single file uploads, so I would prefer to see the bug fixed.
Thanks!
System details:
Ubuntu 14.04.1 LTS
Python 2.7.6
Selenium 2.40.0
PhantomJS 1.9.7
@sanosay Thanks for your response but its not working for me.
@scobal How this code is working for you. I have tried so many times but its not working for me.
I'm still strugling with this issue, not sure exact same phenomenon, though.
My environment is
By the way, this passes with firefox via selenium-server 2.45.0 on MacOSX Yosemite
The following is selenium-server's DEBUG log. I've also got a phantomjs crash report dmp file but don't know how I should report it.
18:16:03.629 DEBUG - Executed: [5ea2c980-dc3d-11e4-add9-cbcaa6114036, sendKeysToElement {id=:wdc:1428311763554, value=[Ljava.lang.String;@7f8cf32c}]
18:16:03.629 INFO - Done: [send keys: 113 [[PhantomJSDriver: phantomjs on LINUX (5ea2c980-dc3d-11e4-add9-cbcaa6114036)] -> css selector: input[name="data\[ExhibitorFile\]\[file1\]"]], [/tmp/f9d15915-e64a-4d77-a6be-b87f9a3a9c87/upload8328876185445477342file/UploadFile]]
18:16:03.629 DEBUG - Finished: POST /session/f9d15915-e64a-4d77-a6be-b87f9a3a9c87/element/113/value
18:16:03.630 DEBUG - Handled by org.openqa.jetty.jetty.servlet.ServletHandler@7bb11784
18:16:03.630 DEBUG - RESPONSE:
HTTP/1.1 200 OK
Date: Mon, 06 Apr 2015 09:16:03 GMT
Server: Jetty/5.1.x (Linux/2.6.32-504.3.3.el6.x86_64 amd64 java/1.8.0_40
Connection: close
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 158
Content-Type: application/json; charset=utf-8
18:16:03.644 DEBUG - new HttpConnection: Socket[addr=/0:0:0:0:0:0:0:1,port=55298,localport=50574]
18:16:03.645 DEBUG - REQUEST from [email protected]:50574:
POST /wd/hub/session/f9d15915-e64a-4d77-a6be-b87f9a3a9c87/elements HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: application/json
Host: localhost:50574
User-Agent: libwww-perl/6.13
Content-Type: application/json; charset=utf-8
Content-Length: 46
18:16:03.645 DEBUG - Try HttpContext[/wd,/wd],0
18:16:03.645 DEBUG - RestishHandler org.openqa.jetty.jetty.servlet.ServletHandler@7bb11784
18:16:03.646 DEBUG - servlet=/hub/*=WebDriver remote server
18:16:03.646 DEBUG - session=null
18:16:03.646 DEBUG - Handling: POST /session/f9d15915-e64a-4d77-a6be-b87f9a3a9c87/elements
18:16:03.647 INFO - Executing: [find elements: By.cssSelector: .cake-error])
18:16:03.648 DEBUG - Executing: findElements [5ea2c980-dc3d-11e4-add9-cbcaa6114036, findElements {using=css selector, value=.cake-error}]
18:16:03.651 DEBUG - CookieSpec selected: best-match
18:16:03.652 DEBUG - Auth cache not set in the context
18:16:03.652 DEBUG - Connection request: [route: {}->http://localhost:31728][total kept alive: 1; route allocated: 1 of 2000; total allocated: 1 of 2000]
18:16:03.656 DEBUG - Connection leased: [id: 0][route: {}->http://localhost:31728][total kept alive: 0; route allocated: 1 of 2000; total allocated: 1 of 2000]
18:16:03.657 DEBUG - Stale connection check
18:16:03.659 DEBUG - http-outgoing-0 << "end of stream"
18:16:03.659 DEBUG - Stale connection detected
18:16:03.659 DEBUG - http-outgoing-0: Close connection
18:16:03.660 DEBUG - Opening connection {}->http://localhost:31728
18:16:03.661 DEBUG - Connecting to localhost/127.0.0.1:31728
18:16:03.664 DEBUG - Connection established 127.0.0.1:60754<->127.0.0.1:31728
18:16:03.664 DEBUG - Executing request POST /session/5ea2c980-dc3d-11e4-add9-cbcaa6114036/elements HTTP/1.1
18:16:03.664 DEBUG - Target auth state: UNCHALLENGED
18:16:03.664 DEBUG - Proxy auth state: UNCHALLENGED
18:16:03.665 DEBUG - http-outgoing-0 >> POST /session/5ea2c980-dc3d-11e4-add9-cbcaa6114036/elements HTTP/1.1
18:16:03.677 DEBUG - http-outgoing-0 >> Content-Type: application/json; charset=utf-8
18:16:03.679 DEBUG - http-outgoing-0 >> Content-Length: 46
18:16:03.681 DEBUG - http-outgoing-0 >> Host: localhost:31728
18:16:03.681 DEBUG - http-outgoing-0 >> Connection: Keep-Alive
18:16:03.682 DEBUG - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.6 (java 1.5)
18:16:03.682 DEBUG - http-outgoing-0 >> Accept-Encoding: gzip,deflate
18:16:03.682 DEBUG - http-outgoing-0 >> "POST /session/5ea2c980-dc3d-11e4-add9-cbcaa6114036/elements HTTP/1.1[\r][\n]"
18:16:03.683 DEBUG - http-outgoing-0 >> "Content-Type: application/json; charset=utf-8[\r][\n]"
18:16:03.683 DEBUG - http-outgoing-0 >> "Content-Length: 46[\r][\n]"
18:16:03.684 DEBUG - http-outgoing-0 >> "Host: localhost:31728[\r][\n]"
18:16:03.684 DEBUG - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
18:16:03.684 DEBUG - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.6 (java 1.5)[\r][\n]"
18:16:03.684 DEBUG - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
18:16:03.684 DEBUG - http-outgoing-0 >> "[\r][\n]"
18:16:03.684 DEBUG - http-outgoing-0 >> "{"using":"css selector","value":".cake-error"}"
PhantomJS has crashed. Please read the crash reporting guide at https://github.com/ariya/phantomjs/wiki/Crash-Reporting and file a bug report at https://github.com/ariya/phantomjs/issues/new with the crash dump file attached: /tmp/15fa89b0-7a09-bc96-413db398-7ecaec0d.dmp
18:16:03.776 DEBUG - http-outgoing-0 << "end of stream"
18:16:03.780 DEBUG - http-outgoing-0: Close connection
18:16:03.785 DEBUG - http-outgoing-0: Shutdown connection
18:16:03.788 DEBUG - Connection discarded
18:16:03.789 DEBUG - http-outgoing-0: Close connection
18:16:03.789 DEBUG - Connection released: [id: 0][route: {}->http://localhost:31728][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
18:16:05.804 DEBUG - CookieSpec selected: best-match
18:16:05.804 DEBUG - Auth cache not set in the context
18:16:05.804 DEBUG - Connection request: [route: {}->http://localhost:31728][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
18:16:05.804 DEBUG - Connection leased: [id: 1][route: {}->http://localhost:31728][total kept alive: 0; route allocated: 1 of 2000; total allocated: 1 of 2000]
18:16:05.804 DEBUG - Opening connection {}->http://localhost:31728
18:16:05.805 DEBUG - Connecting to localhost/127.0.0.1:31728
18:16:05.807 DEBUG - Connect to localhost/127.0.0.1:31728 timed out. Connection will be retried using another IP address
18:16:05.807 DEBUG - Connecting to localhost/0:0:0:0:0:0:0:1:31728
18:16:05.809 DEBUG - http-outgoing-1: Shutdown connection
18:16:05.809 DEBUG - Connection discarded
18:16:05.809 DEBUG - http-outgoing-1: Close connection
18:16:05.809 DEBUG - Connection released: [id: 1][route: {}->http://localhost:31728][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
18:16:05.816 DEBUG - Exception: [5ea2c980-dc3d-11e4-add9-cbcaa6114036, findElements {using=css selector, value=.cake-error}]
18:16:05.906 DEBUG - Finished: POST /session/f9d15915-e64a-4d77-a6be-b87f9a3a9c87/elements
18:16:05.915 DEBUG - Handled by org.openqa.jetty.jetty.servlet.ServletHandler@7bb11784
18:16:05.915 DEBUG - RESPONSE:
HTTP/1.1 500 Internal Server Error
Date: Mon, 06 Apr 2015 09:16:03 GMT
Server: Jetty/5.1.x (Linux/2.6.32-504.3.3.el6.x86_64 amd64 java/1.8.0_40
Connection: close
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 1678
Content-Type: application/json; charset=utf-8
Error while executing command: findElements: An unknown server-side error occurred while processing the command.: Error communicating with the remote browser. It may have died.
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'localhost.localdomain', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-504.3.3.el6.x86_64', java.version: '1.8.0_40'
Driver info: driver.version: EventFiringWebDriver at apply/../lib/TestNikkei.pm line 156.
18:16:05.947 DEBUG - new HttpConnection: Socket[addr=/0:0:0:0:0:0:0:1,port=55302,localport=50574]
18:16:05.948 DEBUG - REQUEST from [email protected]:50574:
DELETE /wd/hub/session/f9d15915-e64a-4d77-a6be-b87f9a3a9c87 HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: application/json
Host: localhost:50574
User-Agent: libwww-perl/6.13
Content-Type: application/json; charset=utf-8
Content-Length: 2
18:16:05.948 DEBUG - Try HttpContext[/wd,/wd],0
18:16:05.949 DEBUG - RestishHandler org.openqa.jetty.jetty.servlet.ServletHandler@7bb11784
18:16:05.949 DEBUG - servlet=/hub/*=WebDriver remote server
18:16:05.949 DEBUG - session=null
18:16:05.949 DEBUG - Handling: DELETE /session/f9d15915-e64a-4d77-a6be-b87f9a3a9c87
18:16:05.952 INFO - Executing: [delete session: f9d15915-e64a-4d77-a6be-b87f9a3a9c87])
18:16:05.953 DEBUG - Executing: quit [5ea2c980-dc3d-11e4-add9-cbcaa6114036, quit {}]
18:16:05.957 DEBUG - CookieSpec selected: best-match
18:16:05.958 DEBUG - Auth cache not set in the context
18:16:05.958 DEBUG - Connection request: [route: {}->http://localhost:31728][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
18:16:05.959 DEBUG - Connection leased: [id: 2][route: {}->http://localhost:31728][total kept alive: 0; route allocated: 1 of 2000; total allocated: 1 of 2000]
18:16:05.960 DEBUG - Opening connection {}->http://localhost:31728
18:16:05.961 DEBUG - Connecting to localhost/127.0.0.1:31728
18:16:05.964 DEBUG - Connect to localhost/127.0.0.1:31728 timed out. Connection will be retried using another IP address
18:16:05.966 DEBUG - Connecting to localhost/0:0:0:0:0:0:0:1:31728
18:16:05.969 DEBUG - http-outgoing-2: Shutdown connection
18:16:05.970 DEBUG - Connection discarded
18:16:05.970 DEBUG - http-outgoing-2: Close connection
18:16:05.971 DEBUG - Connection released: [id: 2][route: {}->http://localhost:31728][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
18:16:05.972 DEBUG - Waiting for http://localhost:31728/shutdown
18:16:05.976 DEBUG - Polling http://localhost:31728/shutdown
18:16:05.994 DEBUG - Exception: [5ea2c980-dc3d-11e4-add9-cbcaa6114036, quit {}]
18:16:05.997 DEBUG - Finished: DELETE /session/f9d15915-e64a-4d77-a6be-b87f9a3a9c87
18:16:06.011 DEBUG - Handled by org.openqa.jetty.jetty.servlet.ServletHandler@7bb11784
18:16:06.012 DEBUG - RESPONSE:
HTTP/1.1 500 Internal Server Error
Date: Mon, 06 Apr 2015 09:16:05 GMT
Server: Jetty/5.1.x (Linux/2.6.32-504.3.3.el6.x86_64 amd64 java/1.8.0_40
Connection: close
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 1673
Content-Type: application/json; charset=utf-8
18:16:06.033 INFO - Shutting down...
Is there a fix or work around for this ?
Ubuntu 14.04 / Selenium 2.45 / PhantomJS 2.0
File upload works fine using firefox driver but phantomjs just hangs using :
driver.findElement(By.CssSelector("input[type='file']")).sendKeys("path/to/file");
the work around suggested does not hang but does not upload a file either :
((PhantomJSDriver)driver).executePhantomJS("var page = this; page.uploadFile('input[type=file]', '/path/to/file');");
Doesn't work for me either with Mac OS Yosemite / Selenium 2.45 / PhantomJS 1.9.16 .
+1
Mac OS Yosemite / Selenium 2.44.0 / PhantomJS 2.0.0
None of the suggested work-arounds worked so I ended up going back 1.9.8
What a PITA that was - a prebuilt executable should not have been that difficult to locate
It may be just me but 1.9.8 seems significantly slower that 2.0
This issue makes any higher version of phantomjs 2 a non-starter
Everyone who's experiencing this problem -- we would really really appreciate it if you could take some time to construct a minimal, self-contained test case. All of the scenarios described above are complicated enough that I don't even know where to begin trying to reproduce this bug myself; in fact, it might be that there are four or five different bugs all tangled up in here. Thanks in advance.
Note that the version of Webkit embedded in 1.x is very old and riddled with bugs; any fix we eventually develop would be for 2.0 only.
Same issue here. Ubuntu 14.04 Selenium 2.45.0 PhantomJS 1.9.0
self-containing test case ( using selenium ) is that easy : a blank page with a single input[type="file"], and going
driver.findElement(By.CssSelector("input[type='file']")).sendKeys("path/to/file");
never resolves.
wayofspark has it - not much more
way - I have it working with 1.9.8 - maybe this an old problem that was fixed between 1.9.0 and 2.0 ?
track down 1.9.8 and see if that fixes the problem - I found a prebuilt on Launchpad.net - had to extract from a .deb.
Hi All,
I am also stuck with the same problem, i am trying to post an image to a facebook group.
But when it comes to multipart file upload the system i have written is working fine with the firefox driver, but when I am trying to do the same things(image upload) it is not working with phantomjs 1.9.8 and not even with phantomjs 2.0.
I am using following code:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class seleniumautiitfb {
static WebDriver driver;
public static void main(String args[]) throws InterruptedException
{
//driver =new FirefoxDriver();
File file = new File("C:/Users/DellPC/Desktop/phantomjs-1.9.8-windows/phantomjs-1.9.8-windows/phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
driver = new PhantomJSDriver();
driver.manage().window().maximize();
System.out.println("111111111111111111111111111");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.facebook.com/");
driver.findElement(By.id("email")).sendKeys(Your facebook id here);
driver.findElement(By.id("pass")).sendKeys(your facebook password here);
driver.findElement(By.id("loginbutton")).click();
System.out.println("222222222222222222222222222");
driver.get(one of your facebook group here);
System.out.println("2222222222222bbbbbbbbbbbbbbbbb");
driver.findElement(By.linkText("Add Photo / Video")).click();
System.out.println("2222222222222aaaaaaaaaaaaaaaaaaaaaaa");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.name("composer_unpublished_photo[]")));
System.out.println("2222222222222222222222ccccccccccccccccccccc");
// myDynamicElement.click();
try {
String url=Path to an image on your system;
System.out.println("222222222222222222222ddddddddddddddddddddddddd");
// Runtime.getRuntime().exec("E:\ScriptToUploadFile\ScriptToUploadFile.exe "+url);
myDynamicElement.sendKeys(url);
System.out.println("3333333333333333333333333333333333333");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread.sleep(30000);
//driver.wait(10000);
System.out.println("444444444444444444444444444444444444444444");
System.out.println("full page is: "+driver.getPageSource());
WebElement myDynamicpostbutton = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("(//button[@class='_42ft _4jy0 _11b _yo _4jy3 _4jy1 selected _51sy'])")));
//WebElement myDynamicpostbutton = driver.findElement(By.xpath("(//button[@value='1'])[10]"));
System.out.println("the button element is "+myDynamicpostbutton.isDisplayed());
myDynamicpostbutton.submit();
System.out.println("55555555555555555555555555555555555555555555555555");
System.out.println("before element is "+myDynamicpostbutton);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
System.out.println("after element is "+myDynamicpostbutton);
myDynamicpostbutton.click();
System.out.println("6666666666666666666666666666666666666666666666");
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Can any one help me , how to do this headlessly.
thanks
can anyone please update the code given in last comment for phantomjs to post an image to facebook groups.
Thanks
@ankitg1559 This is a GhostDriver issue.
See my comment at https://github.com/ariya/phantomjs/issues/10993#issuecomment-52855108
I'm using Nightwatch to write my tests which drives PhantomJS via GhostDriver. In order to overcome the issue with file inputs that allow multiple files to be uploaded I use the execute() command to run Javascript in the context of the browser to remove the multiple attribute from the form input. Then I can at least upload 1 file, but I'm still unable to test multiple file uploads with PhantomJS and GhostDriver.
I suggest you take a look at the related issue in GhostDriver here: https://github.com/detro/ghostdriver/issues/282
Hope this helps you!
Hi Richard-flosi,
Thanks a-lot that actually worked for me.
Thanks
:+1: Awesome!
I still have the same issue and in my case file upload is not multiple.
I use nightwatch and its code works perfectly in firefox but hangs execution in phantomJS 2.0.
I already tried all the solutions i found for today - changing locator to XPath doesn't solved problem. Input is visible and everything should work perfectly but somehow it is not... Executing with parameter --verbose doesn't provided me with any useful information because it just hangs without any messages provided.
Here is a code snippet with comments:
browser
.url(params.baseUrl + '/my/account/')
.waitForElementVisible('div.env-upload-box > div',2000)//waiting till content loads
.click('div.env-upload-box > div')//this opens modal with input
.execute('$(".button_upload input").css("visibility", "visible");') //this makes input visible
.setValue('.button_upload input',absolutePath) //here it hangs deadly
.click('.action .upload_button')//this never reached in phantomJS
.waitForElementNotVisible('div.modal-dialog',10000)
.end()
this is last lines from execution log where it hangs:
INFO Request: POST /wd/hub/session/bd687cf7-c8ae-45b2-b248-9d09e0d8a4cd/execute
- data: {"script":"$(\".button_upload input\").css(\"visibility\", \"visible\");","args":[]}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":84}
INFO Response 200 POST /wd/hub/session/bd687cf7-c8ae-45b2-b248-9d09e0d8a4cd/execute{ state: 'success',
sessionId: 'bd687cf7-c8ae-45b2-b248-9d09e0d8a4cd',
hCode: 165226740,
value: null,
class: 'org.openqa.selenium.remote.Response',
status: 0 }
LOG → Completed command execute (14 ms)
INFO Request: POST /wd/hub/session/bd687cf7-c8ae-45b2-b248-9d09e0d8a4cd/element
- data: {"using":"css selector","value":".button_upload input"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":55}
INFO Response 200 POST /wd/hub/session/bd687cf7-c8ae-45b2-b248-9d09e0d8a4cd/element{ state: 'success',
sessionId: 'bd687cf7-c8ae-45b2-b248-9d09e0d8a4cd',
hCode: 1701254315,
value: { ELEMENT: '9' },
class: 'org.openqa.selenium.remote.Response',
status: 0 }
INFO Request: POST /wd/hub/session/bd687cf7-c8ae-45b2-b248-9d09e0d8a4cd/element/9/value
- data: {"value":["D",":","\\","r","e","p","o","\\","s","m","m","-","u","i","\\","a","p","p","\\","i","m","a","g","e","s","\\","a","l","e","x","a","n","d","r","a",".","j","p","g"]}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":172}
as you can see from above no visible problems with path to file or visibility of inputs.
Hi xenonLX,
Can you please provide the html first.
Thanks
here is the html of modal with input:
<div class="modal-body">
<button class="modal-close" type="button" ng-disabled="$flow.isUploading()" ng-click="close()">
<span class="sr-only" translate=""><span class="ng-scope">Close</span></span>
</button>
<div style="background: none repeat scroll 0% 0% rgb(244, 247, 249);" class="upload-area" ng-style="{'background': (!$flow.files.length ? '#f4f7f9' : 'none')}" flow-drop="" flow-drag-enter="class='drop'" flow-drag-leave="class=''" flow-drop-enabled="dropEnabled" ng-class="class">
<div class="controls" ng-hide="$flow.files.length">
<h2 translate=""><span class="ng-scope">Drag photo</span></h2>
<span class="or" translate=""><span class="ng-scope">— or —</span></span>
<span class="form-button button_upload" flow-btn="" translate=""><span class="ng-scope">Choose photo</span><input style="visibility: hidden; position: absolute;" type="file"></span>
</div>
<div class="preview ng-hide" ng-show="$flow.files.length">
<img class="ng-isolate-scope" crop="" flow-img="$flow.files[0]" selected="selected(cords)">
<!-- ngIf: target === 'cover' -->
<div class="progress progress-striped" ng-class="{'active': $flow.isUploading()}">
<div style="width: 0%;" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" ng-style="{width: ($flow.progress() * 100) + '%'}"></div>
</div>
<div class="action">
<a class="btn btn-small btn-success upload_button" ng-hide="$flow.isUploading()" ng-click="$flow.upload()" translate=""><span class="ng-scope">Upload</span></a>
<div class="button-wrapper">
<span class="btn btn-small btn-info change_button" ng-hide="$flow.isUploading()" flow-btn="" translate=""><span class="ng-scope">Change</span><input style="visibility: hidden; position: absolute;" type="file"></span>
<span class="btn btn-small btn-info cancel_button" ng-hide="$flow.isUploading()" ng-click="$flow.cancel()" translate=""><span class="ng-scope">Cancel</span></span>
</div>
<span class="spinner ng-scope ng-hide" ng-show="$flow.isUploading()" us-spinner="{lines: 11, radius:10, width:5, length: 7, color: '#ff6a4c', left: 0, top: 0}"><div role="progressbar" style="position: absolute; width: 0px; z-index: 2000000000; left: 0px; top: 0px;" class="spinner"><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-0-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(0deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-1-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(32deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-2-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(65deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-3-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(98deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-4-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(130deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-5-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(163deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-6-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(196deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-7-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(229deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-8-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(261deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-9-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(294deg) translate(10px, 0px); border-radius: 2px;"></div></div><div style="position: absolute; top: -2px; opacity: 0.25; animation: 1s linear 0s normal none infinite running opacity-100-25-10-11;"><div style="position: absolute; width: 12px; height: 5px; background: none repeat scroll 0% 0% rgb(255, 106, 76); box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1); transform-origin: left center 0px; transform: rotate(327deg) translate(10px, 0px); border-radius: 2px;"></div></div></div></span>
<!--<a class="btn btn-small btn-info" ng-click="$flow.cancel()">Change Photo</a>-->
<a class="btn btn-small btn-danger ng-hide" ng-click="$flow.upload()" ng-show="$flow.error" translate=""><span class="ng-scope">Retry</span></a>
</div>
</div>
</div>
</div>
@XenonLX What's your Nightwatch test look like?
here is the whole test suite:
module.exports = {
tags: ['login','image','upload'],
'LogIN': function (browser) {
var params = browser.globals;
browser
.url(params.baseUrl + '/?city=L')
.waitForElementVisible('body', 1000)
.assert.elementPresent('.login-link > span:nth-child(1)')
.click('.login-link > span:nth-child(1)')
.assert.elementPresent('input[name=email]')
.assert.elementPresent('input[name=password]')
.waitForElementVisible('input[name=email]', 1000)
.setValue('input[name=email]', params.signup.email)
.setValue('input[name=password]', params.signup.password)
.click('button[type=submit]')
.waitForElementVisible('#account', 5000)
.assert.elementPresent('#account');
},
'Go to my account and upload photo': function (browser) {
var path = require('path');
var params = browser.globals;
fileToUpload = '../../app/images/alexandra.jpg',
absolutePath = path.resolve(__dirname, fileToUpload);
console.log(absolutePath);
browser
.url(params.baseUrl + '/my/account/')
.waitForElementVisible('.profile-title > h2:nth-child(1) > span:nth-child(1)', 5000)
.assert.containsText('.profile-title > h2:nth-child(1) > span:nth-child(1)', 'Hello')
.click('.tab-nav > li:nth-child(1) > a:nth-child(1)')
.waitForElementVisible('div.env-upload-box > div',2000)
.click('div.env-upload-box > div')
.execute('$(".button_upload input").css("visibility", "visible");')
.setValue('.button_upload input',absolutePath)
.click('.action .upload_button')
.waitForElementNotVisible('div.modal-dialog',10000)
.end();//add assertion of image for complete test
}
};
@XenonLX Your code looks right. I'm assuming you verified taht absolutePath is getting set correctly as I think that can cause issues if it's not. I'd also make sure your selector for .setValue('.button_upload input',absolutePath) is unique enough and only matches one element. Have you tried adding a callback to your setValue command to see what comes back there or turn on verbose logging to see if there are errors in the Selenium log?
@richard-flosi Yes i added that console.log to verify the path to a file and its OK. Yes I ran it in a verbose logging and all seem normal just until it hangs (lines from the verbose logs were written in my first message)... And I didn't tried adding callback to a set value, but i think that it didn't even reach the callback ill do it right now and reply asap.
@richard-flosi As is supposed callback was never executed... I've also covered the case with the wrong path before posting here - i set it to an incorrect value on purpose and PhantomJS handled it as an error correctly.
@XenonLX is your call to .url(params.baseUrl + '/my/account/') necessary?
After login, are you redirected to the account page?
I've had issues with multiple calls to url() using PhantomJS and GhostDriver.
How about asserting that selector is there before trying calling setValue?
@richard-flosi Multiple url's are not the case because i added first one recently (after it already hanged under the phantomJS), i developed test suite using firefox and then changed to phantomJS for CI integration reasons.
After login, are you redirected to the account page?
No, i have to go there manually, ill try to replace it avoiding url's usage if you think it may cause the issue.
How about asserting that selector is there before trying calling setValue?
It's a good point, but i can assure you that in my particular case the selector is present.
@richard-flosi I've replaced second url call by few assertions and got to the account page using click methods to the menu items, it doesn't solved the issue with file upload it still hangs and callback in the setValue is never reached.
ok. I'm out of ideas for now.
as was i when i posted my first post =) Ill have to run it under firefox for now...
@richard-flosi @XenonLX - Did u guys find a work around for the issue? I'm have the exact same issue as @XenonLX. Would love to get some direction. haha
@RongxinZhang I didn't found any, so i kept using Firefox. Make sure your case is not about multifile upload.
@RongxinZhang reverting back to version 1.9.8 solved it for me
It is definitely an issue of phantomjs 2.0. Reverting back to version 1.9.8 partially solved it.
Since the sendKeys() method only works with elements that do not have the multiple attribute included I used the following code to execute javascript before using sendKeys().
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor)driver).executeScript(
"document.getElementsByTagName('input')[0].removeAttribute('multiple');"
);
}
I used the getElementsByTagName to locate the input tag and removed the attribute.
Afterwards I was able to use
driver.findElement(By.xpath("//*[@id='fileupload']/div/div[1]/span[1]/input")).sendKeys("C:\\path\\of\\file");
@XenonLX @germgerm @kasual1 . Yea I reverted it back to 1.9 worked.
@ariya @zackw @kaaloo @richard-flosi @kasual1
Hi!
I created a sample project that stably reproduces the hanging PhantomJS problem:
https://github.com/asolntsev/hanging-phantomjs
Just execute this in command line:
git clone https://github.com/asolntsev/hanging-phantomjs.git
cd hanging-phantomjs
./gradlew
My environment: latest Mac OS, latest PhantomJS 2.1.1, latest selenium webdriver 2.53.0.
I believe this is a PhantomJS issue (not phantomjsdriver or webdriver), because thread dump shows that webdriver is just waiting for a PhantomJS response (indefinitely).
@ariya @zackw Does it help? Can you now fix the problem with hanging PhantomJS?
the onFilePicker callback triggers the response to the client in ghostdriver. this callback is never called when the element has the multiple attribute. see issue #14331. hence ghostdriver freezes and never sends a response back to the client.
/session/<session_id>/file endpoint with the following json{
"selector": "input[name=file]",
"filepath": ["file1", "file2"],
}
/session/<session_id>/phantom/execute endpoint with the following json{
"script": "self.uploadFile('input[name=file]', ['file1', 'file2']);",
"args": [],
}
The issue still exists.
I have tried
element.sendKeys(filePath);
on input element which does not have multiple attribute and it fails to return. Waited long enough and no exception.
As a workaround, this perfectly worked
((PhantomJSDriver) driver).executePhantomJS("var page = this; page.uploadFile('input[type=file]', '" + filePath + "');");
This was a big limitation considering all our selenium tests run on Jenkins headless. Luckily the workaround script works on Windows and Linux too.
Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!
Most helpful comment
@ariya @zackw @kaaloo @richard-flosi @kasual1
Hi!
I created a sample project that stably reproduces the hanging PhantomJS problem:
https://github.com/asolntsev/hanging-phantomjs
Just execute this in command line:
My environment: latest Mac OS, latest PhantomJS 2.1.1, latest selenium webdriver 2.53.0.
I believe this is a PhantomJS issue (not phantomjsdriver or webdriver), because thread dump shows that webdriver is just waiting for a PhantomJS response (indefinitely).
@ariya @zackw Does it help? Can you now fix the problem with hanging PhantomJS?