Exploring the power of Selenium Webdriver in combination with JavaScript

Can someone help me figure out why I'm getting this error message: "Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to org.openqa.selenium.WebElement at canvasdrag.Canvas.main(Canvas.java:57)"

WebElement element = (WebElement)((JavascriptExecutor)driver).executeScript("return window.app.design.DOOR.length");
String text =  element.getText();
System.out.println(text);

Answer №1

Your JavaScript code is returning a number, but it seems like you are attempting to treat this number as a WebElement object, which may not work as expected. It's unclear what your exact intention was, but it could be either:

long hello = (Long)((JavascriptExecutor)driver).executeScript("return window.app.design.DOOR.length");
System.out.println(world);

or:

WebElement hello = (WebElement)((JavascriptExecutor)driver).executeScript(
    "return [something which resolves to a DOM element]");
String world =  hello.getText();
System.out.println(world);

Since I'm not sure what specific element you are trying to access, you will need to replace

[something which resolves to a DOM element]
with the appropriate selector for the element you actually want.

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

Pulling data from a MySQL database using AJAX and PHP to convert it into a JavaScript variable, resulting in

I am attempting to retrieve MySQL data using PHP, convert it to JSON, and then pass it into my JS variables for Chart.js. The JSON generated by PHP appears correct. However, when trying to access the data within my variables, the console is displaying them ...

Error with setting innerHTML property of a null nested div

This issue arises when the element is referenced before the DOM has completely loaded. To combat this, I have ensured that the necessary script runs only after the window has finished loading. Interestingly, if the getElementById() call is for a standalon ...

What is the best way to showcase two SVG clocks on a single webpage?

The issue arises when combining the desktop and mobile versions of the clock script. The first clock works fine on its own, but upon duplicating another set of scripts for the second clock, it encounters display problems. I have appropriately labeled the c ...

Incorporating TWEEN for camera position animations: A complete guide

function adjustCameraPosition(newPosition, animationDuration) { var tween = new TWEEN.Tween( camera.position ) .to( newPosition, animationDuration ) .easing(TWEEN.Easing.Linear.None) .onUpdate(fun ...

Confirmation email verification in Django Selenium tests

I'm having trouble creating a basic login test for my Django application using Selenium for Python. The error message I receive states that the credentials are not valid. I believe this is due to the email confirmation process required by the allauth ...

How can we update the form builder or form group in Angular 2 when making changes to the existing data in a table? I'm a bit confused on how to implement router

<tr *ngFor="let row of categories "> <td>{{row.categoryName}}</td> <td>{{row.visible}}</td> <td>{{row.instanceNumber}}</td> <td> <a class="btn btn-info btn-fill " [routerLink]="['/con ...

Transform array sequences into their own unique sequences

Reorder Array of List to Fit My Custom Order Current Output: [ { "key": "DG Power Output", "value": "6.00", "unit": "kWh", }, { "key": "DG Run Time", "value": "5999999952", "unit": "minutes", }, { "key": "Fuel Level (Before)", "value": "8.00" ...

To avoid the sudden appearance of a div on the screen, React is programmed to wait for the

Struggling with preventing a flashing div in React where the error message renders first, followed by props, and finally the props render. The EventsView component includes the following code: view.js var view; if (_.size(this.props.events) !== 0) { vie ...

Update the section tag upon submission using jQuery on a jQuery Mobile HTML page

I have integrated a jquerymobile template into Dreamweaver 6.0 to create a mobile app interface. The home screen features four buttons - specifically, View, Create, Update, Delete. Upon clicking the Create button, a new screen is opened (each screen corres ...

The functionality of "perfect-scrollbar" (jQuery plugin) may not be properly initialized when the container it is in is being populated by Angular.js

I have a unique setup on my website where I dynamically generate food and drinks menus using a json file with Angular.js. The issue arises with the implementation of "perfect-scrollbar", which seems to require a scroll-wheel event to work properly on these ...

JavaScript watermark with alternating/dual mode

In the following code snippet, I have implemented a function to make window.status switch between displaying "a" and "b." function alternateViaIntrvl() { setInterval('alterStatus()', 500); } var altrCounter = 0; function alerted() { var ...

Utilizing jQuery to fetch the source value of an image when the closest radio button is selected

On my website, I have a collection of divs that display color swatches in thumbnail size images. What I want to achieve is updating the main product image when a user clicks on a radio button by fetching the source value of the image inside the label eleme ...

Adjusting the color of a specific part of a text within a string using

I am trying to update the color of specific keywords within a post. For example: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tempor lacinia urna eget gravida. Quisque magna nulla, fermentum fermentum od #keyword1 #keyword2 #keyword3 ...

AngularJS static list with dynamically changing content

Seeking inspiration on creating an AngularJS information monitor with a maximum of 6 rows. The display should show new rows at the top, pushing out the oldest row from the bottom when there are already 6 rows visible. Rows can also disappear unexpectedly. ...

Exiting the WebDriver after the browser has been closed by the application

Currently, I am in the process of testing a web application using Selenium Webdriver specifically for Internet Explorer. Interestingly, once I sign off from the application, it successfully closes the browser. However, quitting the webdriver triggers a cra ...

Having Trouble Logging into Instagram Using C# Selenium

Hey everyone, I recently helped my mom set up an Instagram account for her work. I wanted to create an auto follower bot for her using Selenium, but every time I try to test it, Instagram locks me out and asks me to try again in a few minutes. The proble ...

Guide on verifying if the dropdown options appear twice in Selenium Webdriver with Java

I'm facing a challenge in my code where I need to determine if the options in a dropdown menu are being displayed twice. I've tried searching for a solution on Google but haven't found anything helpful so far. Here is the snippet of code th ...

Selenium can be utilized to verify that a user has entered the correct email for account recovery purposes

I attempted the following code snippet: search_recover_login_button.click() try: myElem3 = driver.find_element('xpath', '//*locator').text return "You've got your password reset!" in myElem3 except TimeoutExceptio ...

Detecting if the request in Yii Framework 2.0 is coming from an AJAX GET call

While utilizing Yii framework 2.0, I have implemented an AJAX GET jQuery script that references a function within a controller class. $.get('localhost/website/index', {param: 'xxxx'}, function(returnedData){ // some code here..... ...

The error states that the type '() => string | JSX.Element' cannot be assigned to the type 'FC<{}>'

Can someone help me with this error I'm encountering? I am fairly new to typescript, so I assume it has something to do with that. Below is the code snippet in question: Any guidance would be greatly appreciated. const Pizzas: React.FC = () => { ...