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

Selenium returns null ({"ELEMENT":"0"}) on my every element finding attempts. #43

Open
abtvah opened this issue Aug 6, 2013 · 0 comments

Comments

@abtvah
Copy link

abtvah commented Aug 6, 2013

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:

{"status":0,"sessionId":"3a0d5939-595e-40d6-88c8-fe6f22a165dd","value":{"ELEMENT":"0"},"state":null,"class":"org.openqa.selenium.remote.Response","hCode":15920450}

It seems that the element hasn't been found at all. What's wrong here? Any idea?

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

1 participant