Selenium in Perl: Facing a puzzling JavaScript error while attempting to resize window

Utilizing the Perl Selenium package known as WWW::Selenium, I have encountered a perplexing JavaScript error while attempting to resize the browser window. The error message reads:

"Threw an exception: missing ; before statement"
.

Below is the code snippet:

use strict;
use warnings;
use 5.014;
use autodie; 
use warnings qw< FATAL utf8 >;
use Carp;
use Carp::Always;
use WWW::Selenium;

my $url = 'http://www.google.com'; #for example
my $sel = WWW::Selenium->new( host => 'localhost',
   port => 4444,
   browser => '*firefox F:\WIN 7 programs\Web & Internet\Firefox 8 bit\firefox.exe',
   browser_url => $url,
   );
$sel->open( $url );
$sel->wait_for_page_to_load(10000);
my $res = $sel->window_maximize();  # Everything working fine until this point
$res = $sel->get_eval( q{ WebDriver driver = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
   driver.manage().window().setSize(1040,720);} );
   # (Reference: http://stackoverflow.com/questions/1522252/, Eli Colner's post)

The program encounters a crash at this point with the message:

"Threw an exception: missing ; before statement"

If I remove the first line of JavaScript and retain only the second line like so:

$res = $sel->get_eval( q{driver.manage().window().setSize(1040,720);} );

This results in the error: "driver not defined".

I would greatly appreciate any help - Thank you in advance.

Helen

Note: This query has also been posted here:

Answer №1

It appears that there is an issue with the javascript in your code, possibly due to a misunderstanding. The code seems to be based on a Stack Overflow thread discussing how to resize/maximize a Firefox window using Selenium Remote Control:

How to resize/maximize Firefox window during launching Selenium Remote Control?

It seems like you may have mistaken Java for javascript, as Eli Corner's solution relies on Java or C#, which are the language bindings for WebDriver (or Selenium 2) that support the WebDriverBackedSelenium feature. Other language bindings, such as Perl, do not have this capability. Therefore, even if the syntax of the code is correct, it will fail during execution because it is not utilizing javascript (the classes/objects being referenced are not from javascript).

Here are two options for resolving this issue:

  1. Utilize actual javascript code and consider implementing Dave Hunt's solution (from the same Stack Overflow thread), tailored for Perl:

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

  2. Use the Perl WebDriver binding to correctly apply Eli Corner's solution (adapted for Perl), instead of the Selenium (RC) binding currently being used. The Perl WebDriver binding is Selenium::Remote::Driver, not WWW:Selenium. With this approach, you should be able to execute commands like the following (there is no need for the WebDriverBackedSelenium component in Perl, but transitioning from Selenium RC to WebDriver requires switching to Java or C# due to lack of backward compatibility support):

    $driver->set_window_position(0, 0);

    $driver->set_window_size(640, 480);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Mapping various sets of latitudes and longitudes on Google Maps

I am working with multiple latitude and longitude coordinates. var latlngs = [ {lat:25.774252,lng:-80.190262}, {lat:18.466465,lng:-66.118292}, {lat:32.321384,lng:-64.757370}, {lat:25.774252,lng:-80.190262}, ]; The coordinates were ret ...

The window.focus() function does not seem to be functioning as expected when using

I have been trying to use this code snippet to bring the window into focus. It seems to be working smoothly on Internet Explorer, but unfortunately it is not behaving as expected in Firefox. Any tips or recommendations would be greatly welcomed. ((Javas ...

"Including Span icons, glyphs, or graphs within a table cell in AngularJS based on a specified condition or numerical

I'm attempting to incorporate span icons/glyph-icons using Angular within a td before displaying the country. I've utilized the code below to achieve this, but I'm looking for a more dynamic and elegant solution. Your assistance is greatly a ...

The drop-down button unexpectedly disappears when using Bootstrap in combination with jQuery autocomplete

I have some javascript code that is structured like: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Autocompl ...

`Cannot recompile the `Product` model as it has already been compiled. Please try again

I attempted to reference my productSchema within my purchaseSchema but encountered the following error: OverwriteModelError: Cannot overwrite Product model once compiled. What steps can I take to resolve this issue? Here is my product schema: mongoose = ...

Error in sending Ajax form

I have a form that is set up to send data to a server. When the form is in its regular HTML format, everything works smoothly and all data is successfully transmitted to the server without any issues. However, as soon as I switch the form to use AJAX for s ...

Experiencing problems with the Locale setting when utilizing the formatNumber function in Angular's core functionalities

I am having trouble formatting a number in Angular using the formatNumber function from the Angular documentation. Here is my code snippet: import {formatNumber} from '@angular/common'; var testNumber = 123456.23; var x = formatNumber(Numb ...

Tips for changing the state of a toggle button with JavaScript

I need help creating a toggle button. To see the code I'm working on, click here. In my JavaScript code, I am reading the value of a 'checkbox'. If the value is true, I add another div with a close button. When the close button is clicked, ...

The addition of days is producing an incorrect result

When extracting the date from FullCalendar and attempting to edit it, I noticed that moment.js seems to overwrite all previously saved dates. Here is an example of what's happening: var date_start = $calendar.fullCalendar('getView').start.t ...

Conceal the div by clicking outside of it

Is there a way to conceal the hidden div with the "hidden" class? I'd like for it to slide out when the user clicks outside of the hidden div. HTML <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.c ...

React Material Table - issue with data filtering accuracy

Currently in my React project, I am utilizing Material Table. While everything appears to be rendering correctly, the filtering and searching functionalities are not working as expected. To provide more context, below is a sample of the code: ht ...

HTML5 Drag and Drop: How to Stop Drag and Drop Actions from Occurring Between a Browser and Browser Windows

Is it possible to restrict HTML5 Drag & Drop functionality between different browsers or windows? I am currently working on an Angular2 app that utilizes native HTML5 Drag and Drop feature. Is there a way to prevent users from dragging items out of th ...

Looking to convert a jQuery function to plain JavaScript code?

Struggling with my homework, I must apologize for any mistakes in my English. My task involves creating a chat using node.js and I found some code snippets on a website "" which I used successfully. The issue now is that the chat relies on old jQuery libr ...

Submit fresh text input during selenium operation in asp.net

Currently, in my asp.net project, I am attempting to send data to a Selenium web browser from a web form while the Selenium browser is active. For instance, there is a text box and button on my web form. When I enter text and click the button, it triggers ...

The smooth transition of my collapsible item is compromised when closing, causing the bottom border to abruptly jump to the top

Recently, I implemented a collapsible feature using React and it's functioning well. However, one issue I encountered is that when the collapsible div closes, it doesn't smoothly collapse with the border bottom moving up as smoothly as it opens. ...

Setting an HTML element ID on a material-ui component: A step-by-step guide

I have a website that was created using Gatsby.js and incorporates the Material-UI framework. The specific issue at hand is as follows: I am looking to implement Google Tag Manager "Element Visibility" triggers. The goal is for GTM to trigger a Google Ana ...

What steps can be taken to create an electron menu for easily conducting a general search within the current window?

I am searching for a solution to create an electron menu that includes the label "Find..." and performs a general search within the current browser window. While I was successful in adding the option, I am struggling to figure out how to access the browser ...

Obtain the JSON data from the body of the current post request in Express.js

I have been working on retrieving the actual request body JSON in express.js but haven't been successful so far. Most of the resources I found online only show how to access the body of type ReqBody, whereas I am looking for a way to retrieve the actu ...

The onClick event handler fails to trigger in React

Original Source: https://gist.github.com/Schachte/a95efbf7be0c4524d1e9ac2d7e12161c An onClick event is attached to a button. It used to work with an old modal but now, with a new modal, it does not trigger. The problematic line seems to be: <button cla ...

How can I showcase data retrieved from a function using Ajax Datatable?

I have implemented an Ajax function that retrieves data from a PHP file and displays it in a DataTable. Initially, this setup was working fine. However, when I added a new function to the PHP file, my Ajax function stopped retrieving data from the file. I ...