Chaoui05 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks ! I 'am trying to use "target" method from Selenium:Screenshot. I did following code as it explained Selenium::Screenshot:
$elem = $driver->find_element('/html/body/table/tbody/tr[1]/td[3]/di +v/div/div[1]'); my $s = Selenium::Screenshot->new( png => $driver->screenshot, #png => $d->screenshot, target => [{ size => { width => 65, height => 12 }, #=> $elem->get_size, location => { x => 35, y => 5 }, #=> $elem->get_element_loc +ation_in_view }] );
And i have following output in my Shell:
Logout_test died (Not a HASH reference at C:/Strawberry/../Screenshot. +pm line 365, <DATA> line 821.)
I don't understand why i have got this output. I did almost the same thing with "exclude" method and it worked. Thanks for any advice !
*****Lost in translation****TIMTOWTOI****

Replies are listed 'Best First'.
Re: Target method with Selenium::Screenshot
by Corion (Patriarch) on May 31, 2016 at 08:55 UTC

    Your code does not match the documentation. The target option does not take an array reference but a hash reference.

    Instead of

    target => [{ size => { width => 65, height => 12 }, #=> $elem->get_size, location => { x => 35, y => 5 }, #=> $elem->get_element_loc +ation_in_view }]

    pass a hash reference:

    target => { size => { width => 65, height => 12 }, #=> $elem->get_size, location => { x => 35, y => 5 }, #=> $elem->get_element_loc +ation_in_view }

      Hello !

      Thanks for reply Corion

      Perfect it works now even if i have nothing displayed in my Shell. I will dig again.

      So for "exclude" we need to pass in an array the size and location?!

      Thanks again

      *****Lost in translation****TIMTOWTOI****
Re: Target method with Selenium::Screenshot
by Don Coyote (Hermit) on May 31, 2016 at 10:03 UTC

    Hello Chaoui05

    Your recent posts have queried storage in Arrays, and shown attempts to store Arrays in Hashes, and vice versa.

    An array is indexed in an Ordered manner, typically from $array_element[0] to $array_element[-1]. Where the negative sign indicates to enumerate reversely from the end of the array.

    An hash is a variant of an array. It is an Associated Array, where the elements are treated as key/value pairs. The indices are not integers, they are static strings, and called keys. This confers the attribute of being Un-ordered and can be useful for clarity, where the element is named recognisably, rather than indexed by number. $hash_element{ $key =~ /\A[_0-9a-zA-Z]+\z/ } = $value

    Importantly to note, arrays (inc. hashes) can only hold scalar elements. To situate an array as an element of an array, the array is assigned to a scalar variable in the form of a reference.

    Practically, by usage you come to learn the difference, the usual problems occurring when trying to access or assign to an array/hash ref. Where the access or assignment is of the wrong type. As attested to by the error message - (Not a HASH reference at ... )

    Try these explanations, to help get a clearer understanding of the context of the data. I say context, as you can also apply the array sigil to the front of the array access to access a list of elements within an array rather than only one element. @array_elements[ 0 .. 3 ]

    Further, Objects are a reference to any data type, that can be referenced. But are also associated to a namespace or package through Bless, essentially a named reference. As a fairly simple overview. This means that they can also be stored in arrays, as references, by intention, are scalars.


    Bless my $CODEREF, Classy
      Hello ! Thanks for this useful post. It would be appreciable for the future.
      *****Lost in translation****TIMTOWTOI****

        You are welcome PublicAccess Chaoui05 :D