When a user clicks on JavaScript, it will return true if clicked and false if

Currently working with selenium Java code and incorporating JavaScript execution using the executeScript method, as seen below:

     WebElement menu = driver.findElement(By.cssSelector(string1));
     ((JavascriptExecutor) driver).executeScript("arguments[0].click();", menu);

I am aiming to determine if an element is clickable. If the button is disabled, the click event will not fire, so I require a flag. The issue lies in the fact that a click event in JS returns undefined.

Thus, I need to implement a flag within my executeScript like so:

     Object flag_to_stop  = ((JavascriptExecutor) driver).executeScript("<<something here if returns true string else returns false string>>, menu);

    while (Object.toString.equals(<<true string>>))

This way, I can run a while loop and break out of it if flag_to_stop is false;

Open to any suggestions folks!

Please note, this question pertains more to JavaScript, with all the provided Java code for reference.

Answer №1

Here is a suggestion you might consider:

  boolean stopFlag = false;
  try{
    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", menu);
    stopFlag = true;
  }
  catch(Exception e){
    stopFlag = false;
  }

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

Steps to enable ng-model input HTML in AngularJS

I am working on an HTML code snippet that includes a form input for audio link. However, when I try to enter a URL in the input field and submit the form, I encounter the following errors: <div class="inner-content-linkaudio"> <label for="linka ...

What is the typical approach of JavaScript frameworks towards the 304 not-modified response?

Wondering about the inner workings of Jquery and web development in general. When a JavaScript file is requested and the server sends a 304 not-modified response, how does a framework handle it: Does it load the JS file from cache and run it? Or does it ...

Building nested components with Vue.js involves creating a complex routing structure within the architecture

Utilizing vue.js for my administration app, I aim to create a highly modular UI architecture. Therefore, I have structured and enclosed the Header, Body, Sidebar, and Main in single file components as illustrated below. Tree App - Header - dynamic cont ...

What could be causing my bounce animation to begin 50 pixels higher than its intended starting point?

Trying to create a bouncing effect on text Check out my attempt here. It seems like the bug is in this area. @keyframes bounce{ 0%, 40%{ transform:scale(2,.5) translate(0,100px); } 45%,55%{ transform:translate(0,-50px); } 55%, 100%{ ...

Modify the transition and design of two progress bars

I'm having an issue with merging two Bootstrap progress bars into one. Initially, the first progress bar appears when the page loads and hides after data is loaded. At the same time, the second progress bar shows up. However, the transition animation ...

Having trouble selecting the clicked element after a successful Ajax call, especially when there are multiple elements with the same name

When dealing with multiple elements that share the same class name, I am attempting to target the 'clicked' element upon a successful Ajax return. <td data-name='tom' class="status"><a href="">click< ...

Error: Unable to locate module: 'fs' in Next.js

import nookies from 'nookies'; import { firebaseAdmin } from "../firebaseAdmin"; import { TChildren } from "../types/app/app.types"; interface Props { children: TChildren; } export default function ProtectedRoute(props ...

Use the Vue `this.$router.push` method inside a setTimeout function

I have a landing page '/' that users will see first when they visit our website. I want to display a loading wheel for 5 seconds before automatically redirecting them to the login page '/login'. My Landing.vue page in Vue and Bulma.io ...

Despite implementing componentDidMount, the setState function is failing to update an initialized array state property

I have checked out similar questions such as : Why isn't this.setState updating the state property? Issue with this.setState not updating state Understanding that setState operates asynchronously is key. This snippet showcases my code: import Rea ...

Issue Encountered when Trying to Open Edge Browser with Robot Framework Selenium

When attempting to open the browser for Edge using the Robot Framework selenium keyword, an error message was received stating: "WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH" The following librar ...

Tips for Iterating through JSON Data and Parsing without an Array in a JSON document

My current code successfully parses JSON data with an array, but I'm facing a dilemma when dealing with JSON data that does not have an array structure. CONCERN/ISSUE I am unsure how to iterate through a JSON without an array. How can I loop t ...

What is preventing me from utilizing a dynamic import while working with Nuxt3?

I'm currently working on developing a component that allows me to dynamically import icons based on the provided icon name using unplugin-icons. However, I'm facing an issue where dynamic imports don't seem to work when the import path is dy ...

Is there a way to track the amount a user scrolls once they have reached the bottom of a page using Javascript?

It's a popular UI pattern on mobile devices to have a draggable element containing a scrollable element. Once the user reaches the end of the scrollable content, further scrolling should transition into dragging the outer element. For example, in this ...

Disabling collapse in Bootstrap 5 is impossible using stopPropagation() when clicking on a particular element

I'm attempting to prevent an element from collapsing/expanding when clicking a checkbox inside it. In my example on codepen, my code worked fine with Bootstrap v4, but after switching to v5, the stopPropagation function doesn't seem to work. Yo ...

Maximizing memory efficiency in Javascript through array manipulation strategy

In the project I am working on, I maintain a history of changes. This history is stored as an array containing objects, each with two arrays as properties. When adding a new history snapshot, it appears as follows: history.push({ //new history moment ...

The functionality of SelectByText (partial) in C# Selenium WebDriver bindings appears to be malfunctioning

I am currently facing an issue using the Selenium WebDriver Extensions in C# to select a value from a select list by matching partial text. Despite trying different approaches, I can't seem to get it to work as expected. Could this be a mistake on my ...

The peculiar characteristics of the dragLeave event in various web browsers

I observed a peculiar behavior while working with drag events in Internet Explorer 11. It seems that adding a 'width' property to the elements triggers the dragLeave event, whereas without it, the event does not fire. Can anyone shed light on why ...

Is there a way to set up gulp without relying on npm when using shared hosting?

While working on my shared hosting, I encountered a roadblock regarding the installation of gulp for compiling LESS assets into CSS. The hosting administrator has declined to install npm, which is essential for setting up gulp. Given this limitation, I am ...

Disconnection between client and server communications

Can communication between two entities be established in this scenario? For example, if a server receives a file upload and determines it is incorrect, can it send an event to the client? The client would then catch the event and manipulate the DOM to dis ...

Locate every instance of items in an array within a string

My files have a structure similar to this: https://i.stack.imgur.com/KyaVY.png When a user conducts a search, they send an array to the backend. This array always includes at least one element. For example, if they send ['javascript'] to the b ...