Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Selenium: Trying to resize window from Perl: getting a mysterious JavaScript error

by HelenCr (Monk)
on Jul 05, 2014 at 16:10 UTC ( #1092375=note: print w/ replies, xml ) Need Help??


in reply to Re: Selenium: Trying to resize window from Perl: getting a mysterious JavaScript error
in thread Selenium: Trying to resize window from Perl: getting a mysterious JavaScript error

Thank you, Corion, for your trustworthy help, as always.
This snippet in the OP:

$res = $sel->get_eval( q{ WebDriver driver = ((WebDriverBackedSelenium +) selenium).getWrappedDriver(); driver.manage().window().setSize(1040,768);} );

does define "driver" ok.

As you can see, when replacing it with:

my $js = q{((WebDriverBackedSelenium) selenium).getWrappedDriver().man +age().window().setSize(1040,720);} ; $sel->get_eval($js):

(as suggested in Matthias' comment here: http://stackoverflow.com/questions/24585497),
it produces the error:

 missing ) in parenthetical

This is typically a javascript error not pointing to a missing parentheses, but instead to invalid javascript, for some reason (sometimes: bad string representation)
(see Slaks' comment here: http://stackoverflow.com/questions/18242512).

This leads me to think that somehow, the Perl WWW::Selenium module is not passing on right the javascript string to the Selenium server.

See here, too: http://geekandpirate.wordpress.com/2010/12/11/missing-in-parenthetical/


Comment on Re^2: Selenium: Trying to resize window from Perl: getting a mysterious JavaScript error
Select or Download Code
Re^3: Selenium: Trying to resize window from Perl: getting a mysterious JavaScript error
by daluu (Initiate) on Jul 07, 2014 at 06:06 UTC
    I see invalid javascript in your code, you made a mistaken assumption. Regarding the referenced SO thread that you base your code on:

    http://stackoverflow.com/questions/1522252/

    what makes you think Eli Corner's answer/solution is "javascript"? That is Java, or C# otherwise, because only those language bindings for WebDriver (or Selenium 2) expose a WebDriverBackedSelenium feature. All other language bindings, including Perl have no such option. So even if the code syntax is correct, on execution it will fail because that's not javascript (or shall I say the referenced classes/objects are not javascript).

    Your options for a solution the way I see it are:

    1. use real javascript code and Dave Hunt's solution (in that same SO thread) ideally should work, adapted for Perl:

    $sel->get_eval("window.resizeTo(1024, 768); window.moveTo(0,0);");

    2. use Perl WebDriver binding to correctly use Eli Corner's solution (adapted for Perl), not Selenium (RC) binding that you are currently using. Perl WebDriver binding is Selenium::Remote::Driver, not WWW:Selenium. You should then be able to do something like this (there is no need for the WebDriverBackedSelenium part in Perl, but it does mean you have to switch off using Selenium RC moving to WebDriver, there's no backward compatibility support, you need Java or C# for that):

    $driver->set_window_position(0, 0);

    $driver->set_window_size(640, 480);

      Thank you, daluu. This sounds good. I will try one or both of these solutions and report back.

      (BTW, sorry for the late response - I was extremely busy in another location, on another project)

      Helen

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1092375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-10-22 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls