PHP-Webdiver also returns null, however to test things out I've written my own script, here is a brief description of the problem:
I have an Ubuntu server running on a VPS with LXDE and Firefox been installed. Also I've started Selenium server using this command:
java -jar selenium-server-standalone-2.33.0.jar
it is now running and listens on localhost port 4444. To connect to selenium server via PHP I use this simple script :
$url = "http://www.amazon.com";
$dc = array("browserName" => "firefox",
"version" => "",
"platform" => "ANY",
"javascriptEnabled" => True);
// To get the session id
$session_id = get_id($dc);
// Open 'amazon.com'
$new_map = "/session/".$session_id."/url";
$result = curl_transfer('POST', array('url' => $url), $new_map);
// Wait until the page completely been loaded
$new_map = "/session".$session_id."/timeouts/implicit_wait";
curl_transfer('POST', array('ms' => 7000), $new_map);
// Find an element, here is the Brazil link at the bottom of the page
$new_map = "/session/".$session_id."/element";
$t = curl_transfer('POST', array('using' => 'link text', 'value' => 'Brazil'), $new_map);
print_r($t);
function curl_transfer ($method, $params, $map){
$path = 'http://localhost:4444/wd/hub'.$map;
$c = curl_init($path);
if ($method === 'POST') {
$encoded_params = json_encode($params);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($c, CURLINFO_HEADER_OUT, true);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, true);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8',
'Accept: application/json',
'Expect:'));
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $encoded_params);
$raw_result = curl_exec($c);
// print_r(curl_getinfo($c));
return (string)$raw_result;
}
if ($method === 'GET') {
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($c, CURLINFO_HEADER_OUT, true);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, true);
$raw_result = curl_exec($c);
// print_r(curl_getinfo($c));
return (string)$raw_result;
}
}
function get_id ($dc){
$result = curl_transfer('POST', array('desiredCapabilities' => $dc), '/session');
$array_result = explode ("\r\n", $result);
$id = str_replace("Location: http://localhost:4444/wd/hub/session/", "", $array_result[6]);
return $id;
}
Everything works fine, the session is being started and Firefox is navigated to Amazon.com,
however with every attempts that I did to find an element I get this as the return object:
PHP-Webdiver also returns null, however to test things out I've written my own script, here is a brief description of the problem:
I have an Ubuntu server running on a VPS with LXDE and Firefox been installed. Also I've started Selenium server using this command:
it is now running and listens on localhost port 4444. To connect to selenium server via PHP I use this simple script :
Everything works fine, the session is being started and Firefox is navigated to Amazon.com, however with every attempts that I did to find an element I get this as the return object:
It seems that the element hasn't been found at all. What's wrong here? Any idea?