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

Employ a data or computed property that relies on the value of the prop. The prop will be changed

I'm trying to open a modal in Vue, but I keep getting this error message in the console from the navigator: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed ...

Refresh Google Maps without showing gray areas on the screen

Currently, I am utilizing the Google Maps API v3 in javascript and frequently reloading the map using an app.get while also incorporating layers and bookmarks via mongodb. Whenever I reload the map to erase everything, a gray background appears in the div ...

Updating State Array dynamically with React JS

I am facing an issue with updating a UseState quantity array in real time. When clicking on a button, a new array is created with updated values for a specific object's quantity. However, the original array does not update immediately. Instead, it onl ...

Is there a way to access or delete a randomly generated document ID in Firestore?

Need help with code to delete an item (current method not working) const docRef = firebase.firestore().collection('users').doc(firebase.auth().currentUser.uid) docRef.collection('tasks').doc(this.task.id).delete() ...

Incorporating FaceBook into a PhoneGap Application

Currently, I am working on integrating Facebook into my phonegap/cordova application. To guide me through the process, I am using the resources provided in this link: https://github.com/davejohnson/phonegap-plugin-facebook-connect/ Even though I have bee ...

Concealing URL in client-side fetch request within Next.js

A contact form built in Next.js makes use of the FormSubmit API to send emails upon clicking the submit button. Below is the code for the onSubmit handler: const handleSubmit = async (e) => { e.preventDefault(); const res = await fetch("https:/ ...

Placing jQuery in the lower part of my HTML templates lacks adaptability

Lately, I've been optimizing my templates by placing the jQuery code link at the end of the template files to ensure fast page load speeds. Along with that, I have specific javascript modules reserved for certain pages that are included within the con ...

Creating an element that remains fixed once it reaches a distance of 50px from the top of the screen

Hey there! I'm working with an html div element that currently scrolls along with the page, but I was wondering how I can make it become fixed once it reaches a distance of 50px from the top of the screen. Any ideas on how to achieve this? Just to pro ...

Tips for overlaying text on the background in Next.js:

I'm currently working on creating an image element with overlay text. Check out my jsx code below: <div className={styles.img}> <img src={src} alt="" /> <p>{`(${size})`}</p> </div> And here is t ...

Setting the default type of an array in props in Vue 2 is a common need for many developers

My Vue component relies on an array of objects as a prop and I always make use of prop validation, especially for setting default values. In this case, my current setup is: props: { items: Array } However, I would prefer it to resemble something lik ...

What is the best way to use an object as a key to filter an array of objects in JavaScript?

My data consists of an array of objects: let allData = [ {title:"Adams",age:24,gender:"male"}, {title:"Baker",age:24,gender:"female"}, {title:"Clark",age:23,gender:"male"}, {title:"Da ...

Making a Zoom effect using p5.js

I have searched for a solution to this question multiple times, but none of the answers I came across seem to work for me. Currently, I am able to allow the user to scale an image with a simple scale(factor) call. However, now I am attempting to implement ...

executing a JavaScript function in a separate .js document

When working with the success callback function in my AJAX post, I encountered an issue trying to call a function from another JavaScript file. Within page1.html: <head> <link href="style.css" rel="stylesheet" type="text/css" /> <s ...

Display a loading screen to the user while Vue lazy loads the content

I am currently implementing lazy loading features for my single-page application using Vue.js and Laravel Mix 5. I am looking for a way to display a loading page to prevent the app from appearing unresponsive while new pages are loading. I attempted to ad ...

What is the best way to ensure that the Next.js app listener is attached before the 'load' event of the window is triggered?

Recently, I started working with next.js, incorporating TypeScript in version 13.5.5. One crucial requirement for the application is that it must be placed within an iframe and communicate with the parent/host through the window.postMessage event. To achie ...

Updating the background image with Jquery is resulting in a distracting flicker effect

Here is a snippet of the script I'm using to create a slider that changes the background image for each image object in a specified time cycle. #Sliderimg - height set to 500px, $("#Sliderimg").css({ "background-image": "url(../Images/" + SliderIma ...

What is the method for enlarging an element without regard to surrounding elements?

I am working on a code where I want the element to zoom in when hovered, completely disregarding its normal flow. By "ignoring its flow," I mean that other elements like tags might obstruct parts of its content. https://i.sstatic.net/NBoez.png https:// ...

Arrange the keys of a map in ascending order, prioritizing special characters and their precedence

JavaScript ES6 Map Example: const map = new Map(); map.set('first', ['1', '2']); map.set('second', ['abc', 'def']); map.set('_third', []); map.set(')(*', []); map.set('he ...

Guide to Producing an Unorthodox 3D Polygon Extruded Form using React-Three-Fiber

Up until now, I've only utilized useBox statement to create 3D rectangles. Is there a method available to generate something like a wooden piece in dimensions of "two by four" with cut ends at specific angles, akin to the image shown below? https://i ...

What are the steps to implement timer control in Ajax using JavaScript?

Hello, I have been trying to establish communication with the server through my application. To achieve this, I made a call to the webservice using AJAX. Now, I am looking to incorporate a time interval in AJAX. Can anyone kindly provide guidance on how ...