ErrorHandler.pm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package Selenium::Remote::ErrorHandler;
  2. use strict;
  3. use warnings;
  4. use Data::Dumper;
  5. use Carp qw(croak);
  6. # We're going to handle only codes that are errors.
  7. use constant STATUS_CODE => {
  8. 7 => {
  9. 'code' => 'NO_SUCH_ELEMENT',
  10. 'msg' => 'An element could not be located on the page using the given search parameters.',
  11. },
  12. 8 => {
  13. 'code' => 'NO_SUCH_FRAME',
  14. 'msg' => 'A request to switch to a frame could not be satisfied because the frame could not be found.',
  15. },
  16. 9 => {
  17. 'code' => 'UNKNOWN_COMMAND',
  18. 'msg' => 'The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.',
  19. },
  20. 10 => {
  21. 'code' => 'STALE_ELEMENT_REFERENCE',
  22. 'msg' => 'An element command failed because the referenced element is no longer attached to the DOM.',
  23. },
  24. 11 => {
  25. 'code' => 'ELEMENT_NOT_VISIBLE',
  26. 'msg' => 'An element command could not be completed because the element is not visible on the page.',
  27. },
  28. 12 => {
  29. 'code' => 'INVALID_ELEMENT_STATE',
  30. 'msg' => 'An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).',
  31. },
  32. 13 => {
  33. 'code' => 'UNKNOWN_ERROR',
  34. 'msg' => 'An unknown server-side error occurred while processing the command.',
  35. },
  36. 15 => {
  37. 'code' => 'ELEMENT_IS_NOT_SELECTABLE',
  38. 'msg' => 'An attempt was made to select an element that cannot be selected.',
  39. },
  40. 19 => {
  41. 'code' => 'XPATH_LOOKUP_ERROR',
  42. 'msg' => 'An error occurred while searching for an element by XPath.',
  43. },
  44. 23 => {
  45. 'code' => 'NO_SUCH_WINDOW',
  46. 'msg' => 'A request to switch to a different window could not be satisfied because the window could not be found.',
  47. },
  48. 24 => {
  49. 'code' => 'INVALID_COOKIE_DOMAIN',
  50. 'msg' => 'An illegal attempt was made to set a cookie under a different domain than the current page.',
  51. },
  52. 25 => {
  53. 'code' => 'UNABLE_TO_SET_COOKIE',
  54. 'msg' => 'A request to set a cookie\'s value could not be satisfied.',
  55. },
  56. };
  57. sub new {
  58. my ($class) = @_;
  59. my $self = {};
  60. bless $self, $class or die "Can't bless $class: $!";
  61. return $self;
  62. }
  63. sub process_error {
  64. my ($self, $resp) = @_;
  65. # TODO: Handle screen if it sent back with the response.
  66. my $ret;
  67. $ret->{'stackTrace'} = $resp->{'value'}->{'stackTrace'};
  68. $ret->{'error'} = $self->STATUS_CODE->{$resp->{'status'}};
  69. return $ret;
  70. }
  71. 1;