Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send_keys(integer) doesn't work. #52

Closed
PenelopeFudd opened this issue Feb 26, 2013 · 4 comments
Closed

Send_keys(integer) doesn't work. #52

PenelopeFudd opened this issue Feb 26, 2013 · 4 comments
Assignees

Comments

@PenelopeFudd
Copy link
Collaborator

I found that
$driver->find_element('serial_id','name')->send_keys(567);
fails with the message
malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "\n\n<tit...") at /usr/local/share/perl/5.14.2/Selenium/Remote/RemoteConnection.pm line 90.

And with strace I found that the selenium server is reporting:
"POST /wd/hub/session/d5141551-2749-4df7-bd54-d24d9ac1791d/element/7/value HTTP/1.1\r\nTE: deflate,gzip;q=0.3\r\nConnection: TE, close\r\nAccept: application/json\r\nHost: localhost:4444\r\nUser-Agent: libwww-perl/6.03\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 15\r\n\r\n{"value":[567]}"

HTTP/1.1 500 org%2Eopenqa%2Eselenium%2EWebDriverException%3A+java%2Elang%2EClassCastException%3A+java%2Elang%2ELong+cannot+be+cast+to+java%2Elang%2EString%0ABuild+info%3A+version%3A+%272%2E30%2E0%27%2C+revision%3A+%27dc1ef9c%27%2C+time%3A+%272013%2D02%2D19+00%3A15%3A27%27%0ASystem+info%3A+os%2Ename%3A+%27Linux%27%2C+os%2Earch%3A+%27amd64%27%2C+os%2Eversion%3A+%273%2E2%2E0%2D37%2Dgeneric%27%2C+java%2Eversion%3A+%271%2E6%2E0%5F27%27%0ADriver+info%3A+driver%2Eversion%3A+unknown\r\nDate: Tue, 26 Feb 2013 17:49:05 GMT\r\nServer: Jetty/5.1.x (Linux/3.2.0-37-generic amd64 java/1.6.0_27\r\nConnection: close\r\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\r\nCache-Control: no-cache\r\nContent-Type: text/html\r\nContent-Length: 1946\r\n\r\n\n\n<title>Error 500 org.openqa.selenium.WebDriverException: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String\nBuild info: version: '2.30.0', revision: 'dc1ef9c', time: '2013-02-19 00:15:27'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-37-generi...

The solution is to make sure it's a string: send_keys($var ."")

@PenelopeFudd
Copy link
Collaborator Author

Add this line to WebElement.pm, line 103:

 map { $_ .= "" } @strings;

@brianmed
Copy link
Collaborator

Do you have example HTML/JS/CSS I can use to verify the problem with PhantomJS?

@ghost ghost assigned brianmed Mar 28, 2013
@PenelopeFudd
Copy link
Collaborator Author

Here is the HTML test case:

<html><head></head><body>
<form><input name="name" type="text"></form>
</body></html>

Here is the perl test program:

#!/usr/bin/perl -w
use strict;
use Selenium::Remote::Driver;

my $driver = Selenium::Remote::Driver->new( remote_server_addr => "localhost", port => 4444, browser_name => "firefox");
$driver->get("http://localhost/form.html");
$driver->find_element("name", "name")->send_keys(1234);
$driver->quit();

Here is the error returned by selenium:

Use of uninitialized value in string eq at /usr/local/share/perl/5.14.2/Selenium/Remote/Driver.pm line 249.
Error while executing command: Server returned error message <html>
<head>
<title>Error 500 org.openqa.selenium.WebDriverException: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:52:59'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-39-generic', java.version: '1.6.0_27'
Driver info: driver.version: unknown</title>
</head>
<body>
<h2>HTTP ERROR: 500</h2><pre>org.openqa.selenium.WebDriverException: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:52:59'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-39-generic', java.version: '1.6.0_27'
Driver info: driver.version: unknown</pre>
<p>RequestURI=/wd/hub/session/eef7e4cd-a369-4e38-bd30-cf05924a2dff/element/0/value</p>
<p><i><small><a href="http://jetty.mortbay.org">Powered by Jetty://</a></small></i></p>                         
</body>
</html>
 instead of data at /usr/local/share/perl/5.14.2/Selenium/Remote/WebElement.pm line 39.

I'm new to github, so I hope I've committed my patch to the right place:
To https://github.com/aivaturi/Selenium-Remote-Driver.git, branch dist-zilla, commit 338872f

@ghost ghost assigned PenelopeFudd Jul 25, 2013
@markstos
Copy link
Collaborator

I think this be closed now that the dist-zilla branch has been merged. Re-open if I'm wrong.

enlewof pushed a commit to enlewof/Selenium-Remote-Driver that referenced this issue Dec 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants