1
0

Driver.pm 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. package Selenium::Remote::Driver;
  2. use strict;
  3. use warnings;
  4. use Data::Dumper;
  5. use Carp qw(croak);
  6. use Selenium::Remote::RemoteConnection;
  7. use Selenium::Remote::Commands;
  8. use Selenium::Remote::WebElement;
  9. use constant FINDERS => {
  10. class => 'ClassName',
  11. class_name => 'ClassName',
  12. css => 'CssSelector',
  13. id => 'Id',
  14. link => 'LinkText',
  15. link_text => 'LinkText',
  16. name => 'Name',
  17. partial_link_text => 'PartialLinkText',
  18. tag_name => 'TagName',
  19. xpath => 'Xpath',
  20. };
  21. our $VERSION = "0.10";
  22. =head1 NAME
  23. Selenium::Remote::Driver - Perl Client for Selenium Remote Driver
  24. =cut
  25. =head1 SYNOPSIS
  26. use Selenium::Remote::Driver;
  27. my $driver = new Selenium::Remote::Driver;
  28. $driver->get('http://www.google.com');
  29. print $driver->get_title();
  30. $driver->quit();
  31. =cut
  32. =head1 DESCRIPTION
  33. Selenium is a test tool that allows you to write
  34. automated web application UI tests in any programming language against
  35. any HTTP website using any mainstream JavaScript-enabled browser. This module is
  36. an implementation of the client for the Remote driver that Selenium provides.
  37. You can find bindings for other languages at this location:
  38. L<http://code.google.com/p/selenium/>
  39. This module sends commands directly to the Server using HTTP. Using this module
  40. together with the Selenium Server, you can automatically control any supported
  41. browser. To use this module, you need to have already downloaded and started
  42. the Selenium Server (Selenium Server is a Java application).
  43. =cut
  44. =head1 USAGE (read this first)
  45. =head2 Server Response Hash
  46. Every method in this module returns either a string or a hash reference. The
  47. string usually means that it has received improper or not received any input.
  48. And that string explains what was wrong. This also means that driver has never
  49. sent any commands to the remote server.
  50. If the methods return a hash reference, that means the driver has sent a command
  51. to the remote server & it has received a response. The driver processes that
  52. response & creates a hash with specific keys & returns it back to the end user.
  53. We shall refer to this hash reference as B<Server Response Hash>. The keys are:
  54. =over
  55. =item cmd_status
  56. The value will either be 'OK' or 'NOTOK'. OK means that server successfully
  57. executed the command & NOTOK means that there was an error encountered on the
  58. server while executing the command. Check cmd_error for further details.
  59. =item cmd_return
  60. This hash key will contain the value returned from the server. It could be of
  61. any data type & each method's POD will list that information.
  62. =item cmd_error
  63. If there was an error on the server while executing the command, this key will
  64. be defined. The value will in turn contain information in a hash with 'stackTrace'
  65. as a key which lists the stack trace of the error encountered on the server &
  66. 'error' which has human readable text of the actual error. It can also contain
  67. a 'screenshot' - a base64 encoded image if the server returns one.
  68. =item session_id
  69. Every successfull command will contain the session id of the current session
  70. against which the command was executed.
  71. =back
  72. So a rule of thumb while invoking methods on the driver is to check whether the
  73. return type is a hash or not. If it is a hash then check for the value of
  74. cmd_status & take necessary actions accordingly. All the method PODs will list
  75. what the cmd_return will contain as that is what an end user is mostly interested
  76. in.
  77. =head2 WebElement
  78. Selenium Webdriver represents all the HTML elements as WebElement, which is
  79. in turn represented by Selenium::Remote::WebElement module. So any method that
  80. deals with WebElements will return and/or expect WebElement object. The POD for
  81. that module describes all the methods that perform various actions on the
  82. WebElements like click, submit etc.
  83. To interact with any WebElement you have to first "find" it, read the POD for
  84. find_element or find_elements for further info. Once you find the required element
  85. then you can perform various actions. If you don't call find_* method first, all
  86. your further actions will fail for that element. Finally, just remember that you
  87. don't have to instantiate WebElement objects at all - they will be automatically
  88. created when you use the find_* methods.
  89. =cut
  90. =head1 FUNCTIONS
  91. =cut
  92. =head2 new
  93. Description:
  94. Constructor for Driver. It'll instantiate the object if it can communicate
  95. with the Selenium RC server.
  96. Input Parameter: 1
  97. desired_capabilities - HASH - Following options are accepted:
  98. Optional:
  99. 'remote_server_addr' - <string> - IP or FQDN of the RC server machine
  100. 'browser_name' - <string> - desired browser string:
  101. {iphone|firefox|internet explorer|htmlunit|iphone|chrome}
  102. 'version' - <string> - desired browser version number
  103. 'platform' - <string> - desired platform:
  104. {WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANY}
  105. 'javascript' - <boolean> - whether javascript should be supported
  106. 'auto_close' - <boolean> - whether driver should end session on remote
  107. server on close.
  108. If no values are provided, then these defaults will be assumed:
  109. 'remote_server_addr' => 'localhost'
  110. 'port' => '4444'
  111. 'browser_name' => 'firefox'
  112. 'version' => ''
  113. 'platform' => 'ANY'
  114. 'javascript' => 1
  115. 'auto_close' => 1
  116. Output:
  117. Remote Driver object
  118. Usage:
  119. my $driver = new Selenium::Remote::Driver;
  120. or
  121. my $driver = new Selenium::Remote::Driver('browser_name' => '10.37.129.2',
  122. 'platform' => 'MAC')
  123. =cut
  124. sub new {
  125. my ( $class, %args ) = @_;
  126. my $ress = new Selenium::Remote::Commands;
  127. # Set the defaults if user doesn't send any
  128. my $self = {
  129. remote_server_addr => delete $args{remote_server_addr} || 'localhost',
  130. browser_name => delete $args{browser_name} || 'firefox',
  131. platform => delete $args{platform} || 'ANY',
  132. port => delete $args{port} || '4444',
  133. version => delete $args{version} || '',
  134. session_id => undef,
  135. remote_conn => undef,
  136. commands => $ress,
  137. auto_close => 1, # by default we will close remote session on DESTROY
  138. };
  139. bless $self, $class or die "Can't bless $class: $!";
  140. if ( defined $args{javascript} ) {
  141. if ( $args{javascript} ) {
  142. $self->{javascript} = JSON::true;
  143. }
  144. else {
  145. $self->{javascript} = JSON::false;
  146. }
  147. }
  148. else {
  149. $self->{javascript} = JSON::true;
  150. }
  151. # Connect to remote server & establish a new session
  152. $self->{remote_conn} =
  153. new Selenium::Remote::RemoteConnection( $self->{remote_server_addr},
  154. $self->{port} );
  155. $self->new_session();
  156. if ( !( defined $self->{session_id} ) ) {
  157. croak "Could not establish a session with the remote server\n";
  158. }
  159. return $self;
  160. }
  161. sub DESTROY {
  162. my ($self) = @_;
  163. $self->quit() if ($self->{auto_close} && defined $self->{session_id});
  164. }
  165. # This is an internal method used the Driver & is not supposed to be used by
  166. # end user. This method is used by Driver to set up all the parameters
  167. # (url & JSON), send commands & receive processed response from the server.
  168. sub _execute_command {
  169. my ( $self, $res, $params ) = @_;
  170. $res->{'session_id'} = $self->{'session_id'};
  171. my $resource = $self->{commands}->get_params($res);
  172. if ($resource) {
  173. my $resp = $self->{remote_conn}
  174. ->request( $resource->{'method'}, $resource->{'url'}, $params );
  175. return $resp;
  176. }
  177. else {
  178. croak "Couldn't retrieve command settings properly\n";
  179. }
  180. }
  181. # A method that is used by the Driver itself. It'll be called to set the
  182. # desired capabilities on the server.
  183. sub new_session {
  184. my $self = shift;
  185. my $args = {
  186. 'desiredCapabilities' => {
  187. 'browserName' => $self->{browser_name},
  188. 'platform' => $self->{platform},
  189. 'javascriptEnabled' => $self->{javascript},
  190. 'version' => $self->{version},
  191. }
  192. };
  193. my $resp =
  194. $self->{remote_conn}
  195. ->request( $self->{commands}->{'newSession'}->{'method'},
  196. $self->{commands}->{'newSession'}->{'url'}, $args, );
  197. if ( ( defined $resp->{'sessionId'} ) && $resp->{'sessionId'} ne '' ) {
  198. $self->{session_id} = $resp->{'sessionId'};
  199. }
  200. else {
  201. croak "Could not create new session";
  202. }
  203. }
  204. =head2 get_capabilities
  205. Description:
  206. Retrieve the capabilities of the specified session.
  207. Output:
  208. 'cmd_return' will contain a hash of all the capabilities.
  209. Usage:
  210. my $capab = $driver->get_capabilities();
  211. print Dumper($capab);
  212. =cut
  213. sub get_capabilities {
  214. my $self = shift;
  215. my $res = {'command' => 'getCapabilities'};
  216. return $self->_execute_command($res);
  217. }
  218. =head2 set_implicit_wait_timeout
  219. Description:
  220. Set the amount of time the driver should wait when searching for elements.
  221. When searching for a single element, the driver will poll the page until
  222. an element is found or the timeout expires, whichever occurs first.
  223. When searching for multiple elements, the driver should poll the page until
  224. at least one element is found or the timeout expires, at which point it
  225. will return an empty list. If this method is never called, the driver will
  226. default to an implicit wait of 0ms.
  227. Input:
  228. Time in milliseconds.
  229. Output:
  230. Server Response Hash with no data returned back from the server.
  231. Usage:
  232. $driver->set_implicit_wait_timeout(10);
  233. =cut
  234. sub set_implicit_wait_timeout {
  235. my ($self, $ms) = @_;
  236. my $res = {'command' => 'setImplicitWaitTimeout'};
  237. my $params = {'ms' => $ms};
  238. return $self->_execute_command($res, $params);
  239. }
  240. =head2 quit
  241. Description:
  242. Delete the session & close open browsers.
  243. Usage:
  244. $driver->quit();
  245. =cut
  246. sub quit {
  247. my $self = shift;
  248. my $res = { 'command' => 'quit' };
  249. $self->_execute_command($res);
  250. $self->{session_id} = undef;
  251. }
  252. =head2 get_current_window_handle
  253. Description:
  254. Retrieve the current window handle.
  255. Output:
  256. String - the window handle
  257. Usage:
  258. print $driver->get_current_window_handle();
  259. =cut
  260. sub get_current_window_handle {
  261. my $self = shift;
  262. my $res = { 'command' => 'getCurrentWindowHandle' };
  263. return $self->_execute_command($res);
  264. }
  265. =head2 get_current_window_handles
  266. Description:
  267. Retrieve the list of window handles used in the session.
  268. Output:
  269. Array of string - list of the window handles
  270. Usage:
  271. print Dumper($driver->get_current_window_handles());
  272. =cut
  273. sub get_window_handles {
  274. my $self = shift;
  275. my $res = { 'command' => 'getWindowHandles' };
  276. return $self->_execute_command($res);
  277. }
  278. =head2 get_current_url
  279. Description:
  280. Retrieve the url of the current page
  281. Output:
  282. String - url
  283. Usage:
  284. print $driver->get_current_url();
  285. =cut
  286. sub get_current_url {
  287. my $self = shift;
  288. my $res = { 'command' => 'getCurrentUrl' };
  289. return $self->_execute_command($res);
  290. }
  291. =head2 navigate
  292. Description:
  293. Navigate to a given url. This is same as get() method.
  294. Input:
  295. String - url
  296. Usage:
  297. $driver->navigate('http://www.google.com');
  298. =cut
  299. sub navigate {
  300. my ( $self, $url ) = @_;
  301. $self->get($url);
  302. }
  303. =head2 get
  304. Description:
  305. Navigate to a given url
  306. Input:
  307. String - url
  308. Usage:
  309. $driver->get('http://www.google.com');
  310. =cut
  311. sub get {
  312. my ( $self, $url ) = @_;
  313. my $res = { 'command' => 'get' };
  314. my $params = { 'url' => $url };
  315. return $self->_execute_command( $res, $params );
  316. }
  317. =head2 get_title
  318. Description:
  319. Get the current page title
  320. Output:
  321. String - Page title
  322. Usage:
  323. print $driver->get_title();
  324. =cut
  325. sub get_title {
  326. my $self = shift;
  327. my $res = { 'command' => 'getTitle' };
  328. return $self->_execute_command($res);
  329. }
  330. =head2 go_back
  331. Description:
  332. Equivalent to hitting the back button on the browser.
  333. Usage:
  334. $driver->go_back();
  335. =cut
  336. sub go_back {
  337. my $self = shift;
  338. my $res = { 'command' => 'goBack' };
  339. return $self->_execute_command($res);
  340. }
  341. =head2 go_back
  342. Description:
  343. Equivalent to hitting the forward button on the browser.
  344. Usage:
  345. $driver->go_forward();
  346. =cut
  347. sub go_forward {
  348. my $self = shift;
  349. my $res = { 'command' => 'goForward' };
  350. return $self->_execute_command($res);
  351. }
  352. =head2 refresh
  353. Description:
  354. Reload the current page.
  355. Usage:
  356. $driver->refresh();
  357. =cut
  358. sub refresh {
  359. my $self = shift;
  360. my $res = { 'command' => 'goForward' };
  361. return $self->_execute_command($res);
  362. }
  363. sub execute_script {
  364. my ( $self, $script, @args ) = @_;
  365. if ($self->javascript) {
  366. if ( not defined $script ) {
  367. return 'No script provided';
  368. }
  369. my $res = { 'command' => 'executeScript' };
  370. # Check the args array if the elem obj is provided & replace it with
  371. # JSON representation
  372. for (my $i=0; $i<@args; $i++) {
  373. if (ref $args[$i] eq 'Selenium::Remote::WebElement') {
  374. $args[$i] = {'ELEMENT' => ($args[$i])->{id}};
  375. }
  376. }
  377. my $params = {'args' => @args};
  378. my $ret = $self->_execute_command($res, $params);
  379. # replace any ELEMENTS with WebElement
  380. if (exists $ret->{'cmd_return'}->{'ELEMENT'}) {
  381. $ret->{'cmd_return'} =
  382. new Selenium::Remote::WebElement(
  383. $ret->{'cmd_return'}->{ELEMENT}, $self);
  384. }
  385. return $ret;
  386. }
  387. else {
  388. return 'Javascript is not enabled on remote driver instance.';
  389. }
  390. }
  391. =head2 screenshot
  392. Description:
  393. Get a screenshot of the current page as a base64 encoded image.
  394. Output:
  395. String - base64 encoded image
  396. Usage:
  397. print $driver->go_screenshot();
  398. =cut
  399. sub screenshot {
  400. my ($self) = @_;
  401. my $res = { 'command' => 'screenshot' };
  402. return $self->_execute_command($res);
  403. }
  404. sub switch_to_frame {
  405. my ( $self, $id ) = @_;
  406. my $json_null = JSON::null;
  407. $id = ( defined $id ) ? $id : $json_null;
  408. my $res = { 'command' => 'switchToFrame' };
  409. my $params = { 'id' => $id };
  410. return $self->_execute_command( $res, $params );
  411. }
  412. sub switch_to_window {
  413. my ( $self, $name ) = @_;
  414. if ( not defined $name ) {
  415. return 'Window name not provided';
  416. }
  417. my $res = { 'command' => 'switchToWindow' };
  418. my $params = { 'name' => $name };
  419. return $self->_execute_command( $res, $params );
  420. }
  421. =head2 get_speed
  422. Description:
  423. Get the current user input speed. The actual input speed is still browser
  424. specific and not covered by the Driver.
  425. Output:
  426. String - One of these: SLOW, MEDIUM, FAST
  427. Usage:
  428. print $driver->get_speed();
  429. =cut
  430. sub get_speed {
  431. my ($self) = @_;
  432. my $res = { 'command' => 'getSpeed' };
  433. return $self->_execute_command($res);
  434. }
  435. =head2 set_speed
  436. Description:
  437. Set the user input speed.
  438. Input:
  439. String - One of these: SLOW, MEDIUM, FAST
  440. Usage:
  441. $driver->set_speed('MEDIUM');
  442. =cut
  443. sub set_speed {
  444. my ( $self, $speed ) = @_;
  445. if ( not defined $speed ) {
  446. return 'Speed not provided.';
  447. }
  448. my $res = { 'command' => 'setSpeed' };
  449. my $params = { 'speed' => $speed };
  450. return $self->_execute_command( $res, $params );
  451. }
  452. sub get_all_cookies {
  453. my ($self) = @_;
  454. my $res = { 'command' => 'getAllCookies' };
  455. return $self->_execute_command($res);
  456. }
  457. sub add_cookie {
  458. my ( $self, $name, $value, $path, $domain, $secure ) = @_;
  459. if ( ( not defined $name )
  460. || ( not defined $value )
  461. || ( not defined $path )
  462. || ( not defined $domain ) )
  463. {
  464. return "Missing parameters";
  465. }
  466. my $res = { 'command' => 'addCookie' };
  467. my $json_false = JSON::false;
  468. my $json_true = JSON::true;
  469. $secure = ( defined $secure ) ? $json_true : $json_false;
  470. my $params = {
  471. 'cookie' => {
  472. 'name' => $name,
  473. 'value' => $value,
  474. 'path' => $path,
  475. 'domain' => $domain,
  476. 'secure' => $secure,
  477. }
  478. };
  479. return $self->_execute_command( $res, $params );
  480. }
  481. sub delete_all_cookies {
  482. my ($self) = @_;
  483. my $res = { 'command' => 'deleteAllCookies' };
  484. return $self->_execute_command($res);
  485. }
  486. sub delete_cookie_named {
  487. my ( $self, $cookie_name ) = @_;
  488. if ( not defined $cookie_name ) {
  489. return "Cookie name not provided";
  490. }
  491. my $res = { 'command' => 'deleteAllCookies', 'name' => $cookie_name };
  492. return $self->_execute_command($res);
  493. }
  494. sub get_page_source {
  495. my ($self) = @_;
  496. my $res = { 'command' => 'getPageSource' };
  497. return $self->_execute_command($res);
  498. }
  499. sub find_element {
  500. my ( $self, $query, $method ) = @_;
  501. if ( not defined $query ) {
  502. return 'Search string to find element not provided.';
  503. }
  504. my $using = ( defined $method ) ? $method : 'xpath';
  505. my $ret;
  506. if (exists FINDERS->{$using}) {
  507. my $res = { 'command' => 'findElement' };
  508. my $params = { 'using' => $using, 'value' => $query };
  509. my $ret_data = $self->_execute_command( $res, $params );
  510. if (defined $ret_data->{'cmd_error'}) {
  511. $ret = $ret_data;
  512. }
  513. else {
  514. $ret_data->{'cmd_return'} = new Selenium::Remote::WebElement($ret_data->{'cmd_return'}->{ELEMENT}, $self);
  515. $ret = $ret_data;
  516. }
  517. }
  518. else {
  519. $ret = "Bad method, expected - class, class_name, css, id, link,
  520. link_text, partial_link_text, name, tag_name, xpath";
  521. }
  522. return $ret;
  523. }
  524. sub find_elements {
  525. my ( $self, $query, $method ) = @_;
  526. if ( not defined $query ) {
  527. return 'Search string to find element not provided.';
  528. }
  529. my $using = ( defined $method ) ? $method : 'xpath';
  530. my $ret;
  531. if (exists FINDERS->{$using}) {
  532. my $res = { 'command' => 'findElements' };
  533. my $params = { 'using' => $using, 'value' => $query };
  534. my $ret_data = $self->_execute_command( $res, $params );
  535. if (defined $ret_data->{'cmd_error'}) {
  536. $ret = $ret_data;
  537. }
  538. else {
  539. my $elem_obj_arr;
  540. my $i = 0;
  541. my $elem_arr = $ret_data->{'cmd_return'};
  542. foreach (@$elem_arr) {
  543. $elem_obj_arr->[$i] = new Selenium::Remote::WebElement($_->{ELEMENT}, $self);
  544. $i++;
  545. }
  546. $ret_data->{'cmd_return'} = $elem_obj_arr;
  547. $ret = $ret_data;
  548. }
  549. }
  550. else {
  551. $ret = "Bad method, expected - class, class_name, css, id, link,
  552. link_text, partial_link_text, name, tag_name, xpath";
  553. }
  554. return $ret;
  555. }
  556. sub find_child_element {
  557. my ( $self, $elem, $query, $method ) = @_;
  558. my $ret;
  559. if ( ( not defined $elem ) || ( not defined $query ) ) {
  560. return "Missing parameters";
  561. }
  562. my $using = ( defined $method ) ? $method : 'xpath';
  563. if (exists FINDERS->{$using}) {
  564. my $res = { 'command' => 'findChildElement', 'id' => $elem->{id} };
  565. my $params = { 'using' => $using, 'value' => $query };
  566. my $ret_data = $self->_execute_command( $res, $params );
  567. if (defined $ret_data->{'cmd_error'}) {
  568. $ret = $ret_data;
  569. }
  570. else {
  571. $ret_data->{'cmd_return'} = new Selenium::Remote::WebElement($ret_data->{'cmd_return'}->{ELEMENT}, $self);
  572. $ret = $ret_data;
  573. }
  574. }
  575. else {
  576. $ret = "Bad method, expected - class, class_name, css, id, link,
  577. link_text, partial_link_text, name, tag_name, xpath";
  578. }
  579. return $ret;
  580. }
  581. sub find_child_elements {
  582. my ( $self, $elem, $query, $method ) = @_;
  583. my $ret;
  584. if ( ( not defined $elem ) || ( not defined $query ) ) {
  585. return "Missing parameters";
  586. }
  587. my $using = ( defined $method ) ? $method : 'xpath';
  588. if (exists FINDERS->{$using}) {
  589. my $res = { 'command' => 'findChildElements', 'id' => $elem->{id} };
  590. my $params = { 'using' => $using, 'value' => $query };
  591. my $ret_data = $self->_execute_command( $res, $params );
  592. if (defined $ret_data->{'cmd_error'}) {
  593. $ret = $ret_data;
  594. }
  595. else {
  596. my $elem_obj_arr;
  597. my $i = 0;
  598. my $elem_arr = $ret_data->{'cmd_return'};
  599. foreach (@$elem_arr) {
  600. $elem_obj_arr->[$i] = new Selenium::Remote::WebElement($_->{ELEMENT}, $self);
  601. $i++;
  602. }
  603. $ret_data->{'cmd_return'} = $elem_obj_arr;
  604. $ret = $ret_data;
  605. }
  606. }
  607. else {
  608. $ret = "Bad method, expected - class, class_name, css, id, link,
  609. link_text, partial_link_text, name, tag_name, xpath";
  610. }
  611. return $ret;
  612. }
  613. sub get_active_element {
  614. my ($self) = @_;
  615. my $res = { 'command' => 'getActiveElement' };
  616. return $self->_execute_command($res);
  617. }
  618. sub describe_element {
  619. my ( $self, $element ) = @_;
  620. #if (not defined $element) {
  621. # return "Element not provided";
  622. #}
  623. #my $res = {'command' => 'desribeElement', 'name' => $element};
  624. #return $self->_execute_command($res);
  625. return "Not yet supported";
  626. }
  627. sub compare_elements {
  628. my ($self, $elem1, $elem2) = @_;
  629. my $res = { 'command' => 'elementEquals',
  630. 'id' => $elem1->{id},
  631. 'other' => $elem2->{id}
  632. };
  633. return $self->_execute_command($res);
  634. }
  635. 1;
  636. __END__
  637. =head1 SEE ALSO
  638. For more information about Selenium , visit the website at
  639. L<http://code.google.com/p/selenium/>.
  640. =head1 BUGS
  641. The Selenium issue tracking system is available online at
  642. L<http://code.google.com/p/selenium/issues/list>.
  643. =head1 AUTHOR
  644. Perl Bindings for Remote Driver by Aditya Ivaturi <ivaturi@gmail.com>
  645. =head1 LICENSE
  646. Copyright (c) 2010 Aditya Ivaturi
  647. Licensed under the Apache License, Version 2.0 (the "License");
  648. you may not use this file except in compliance with the License.
  649. You may obtain a copy of the License at
  650. http://www.apache.org/licenses/LICENSE-2.0
  651. Unless required by applicable law or agreed to in writing, software
  652. distributed under the License is distributed on an "AS IS" BASIS,
  653. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  654. See the License for the specific language governing permissions and
  655. limitations under the License.