Enable JavaScript in Webdriver Selenium to enhance the functionality of your web

I am facing an issue with my Java program and Selenium WebDriver. The script I have does not detect the button "Open device access" because its style is set to "display: none".

Usually, clicking on "Device Access" triggers JavaScript to display the "Open Access device" button. However, it seems that my Firefox WebDriver is not supporting JavaScript. How can I resolve this?


driver.get(baseUrl);
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("XXX");
driver.findElement(By.name("btnlogin")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@href='/mybox/devices/overview.php']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@href='/mybox/devices/satellite.php']")).click();
Thread.sleep(5000);
WebElement element = driver.findElement(By.xpath("//input[@value='Open device access']"));
System.out.println("Element display (Before accordion): "+element.isDisplayed()+"");
driver.findElement(By.id("device_hmi_content_22")).click();
WebElement element2 = driver.findElement(By.xpath("//input[@value='Open device access']"));
System.out.println("Element display (open): "+element2.isDisplayed()+"");

if (isElementPresent(By.xpath("//input[@value='Close device access']")) ) {
    driver.findElement(By.xpath("//input[@value='Close device access']")).click();
    driver.findElement(By.xpath("//input[@value='Open device access']")).click();
    Thread.sleep(5000);
    assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div/p/span")));
    assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input")));
    assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input[2]")));
    Thread.sleep(3000);
    driver.findElement(By.xpath("//input[@value='Close device access']")).click();
    Thread.sleep(5000);
} else {
    // Code to handle if element is not present
}

Although I prefer not to use JavaScript directly in my code, how can I enable JavaScript on my Firefox WebDriver?

The button "Open device access" is currently invisible:

<div id="device_hmi_content_22">
 <div id="accordion_device_hmi_22" class="accordion">
 <h2 class="accHeadline accHeadlineClosed">Device Access</h2>
 <div class="accContent accContentClosed ">
 <div class="submit">
  <input type="button" onclick="onOpenSessionClick()" value="Open device access">
 </div>
  </div>
 </div>

Since the "Open device access" button is not visible, how can I interact with it and make it visible?

Thank you for any assistance provided.

Answer №1

When using Selenium WebDrivers, such as the Firefox driver, JavaScript is designed to work seamlessly without any extra setup required. The problem does not lie in JavaScript not functioning properly. To confirm this, simply open the console during a prolonged pause and execute alert();. Alternatively, dispel any doubts by incorporating the following snippet into your test:

driver.get(baseUrl);
driver.execute('alert();');

If you witness the familiar browser alert, it indicates that JavaScript is indeed operational, implying that the issue may originate from elsewhere.

In my personal experience, I have encountered instances where a click on an element is intercepted by another overlapping element, particularly when dealing with fixed-position elements. If you suspect this might be causing the problem, consider adjusting the elementScrollBehavior to 1.

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

Implementing child components in React using TypeScript and passing them as props

Is it possible to append content to a parent component in React by passing it through props? For example: function MyComponent(props: IMyProps) { return ( {<props.parent>}{myStuff}{</props.parent>} } Would it be feasible to use the new compone ...

Automatic Full-Screen Switching Upon Video Playback in HTML5

Currently, I have a video clip set to play when the timer reaches a certain point. My goal is for the video to automatically enter full-screen mode when it starts playing and return to its original position when it stops, as the timer will continue ticking ...

Unable to open modal using a button in PHP

<?php $result = mysqli_query($con, $sql); while ($row = mysqli_fetch_array($result)) { echo '<tr><td>'; echo '<h5 style="margin-left:6px; color:black;">' . $row['id'] . '</h5> ...

Can you explain the purpose of the window.constructor and global.constructor functions in JavaScript?

Can someone explain the purpose of this function? I've been searching for information but can't find anything. I tested it in Firefox: window.constructor() // TypeError: Illegal constructor new window.constructor() // TypeError: Illegal constru ...

React: Introducing the latest router feature post-login

I'm facing an issue with the Router in React. After a successful login, I am changing the type state in Redux from 0 to 1. However, when I try to make a switch in my App file, I encounter an error. Warning: [react-router] You cannot change <Router ...

Create a single JSON object by searching through two collections in MongoDB

Is it possible for you to assist me in combining data from two collections into one JSON format? Users [ user_id, user_name, city_id ] [ { "name": "Anton", "user_id": 1, "city_id": 1 }, { "name": "Vasiliy", ...

Encountering a Basic React Issue: Unable to Implement @material-ui/picker in Next.js

I'm currently attempting to integrate the @material-ui/pickers library into my Next.js application. In order to incorporate the Picker provider, I followed the guidance provided in the Next.js documentation by adding the _app.js file inside /pages: i ...

Issue specifically with Android 6 WebView - jQuery 1.9.1 where a RangeError is thrown due to the call stack size being exceeded

An error message "Uncaught RangeError Maximum call stack size exceeded" is causing a web application to fail in the jQuery-1.9.1 extend() function, but strangely it only occurs on Android 6. The application runs smoothly on all other platforms such as Des ...

Upon sending a POST request to http://localhost:5000/getData, a 404 error (Not Found) was encountered while using axios

As a newcomer to react and node.js, I have set up a fake server running on port 5000 with an API (http://localhost:5000/getData) that contains a hardcoded array of objects. My goal is to add a new object to this API from my react frontend running on port 3 ...

Encountering a local error in setting an [ ] in a Selenium web scraping tool

Recently, I came across a piece of Python code that has left me puzzled as I do not have much background in this language. The issue at hand involves an unbound local error and it seems like a trivial mistake on my part. UnboundLocalError ...

What is the reason javascript struggles to locate and replace strings with spaces in a URL?

Let me begin by sharing the code I'm currently working on so that you can easily follow my explanations. Apologies for the French language used, as this website is being developed for a French-speaking school. I have eliminated irrelevant sections fro ...

verification tool for a less file's syntax

Searching for a tool to validate a specific less file at the syntax level. The issue lies in the validator not recognizing dependencies or detecting declared mixins. Many existing less processors do not work due to missing dependencies that cannot be prov ...

Trouble with exporting and importing an Express application

Starting with a simple Express example of 'Hello World', I am looking to refactor the code into separate files for configuration and routing. var express = require('express'); var app = express(); app.get('/', function (req, ...

How can one extract the text specifically from the immediate element excluding any text from its sub-nodes?

<li class="lvprice prc"> <span class="bold"> $252.00 <div class="medprc"> <span class="prcVS">Trending at</span> <span class="median"> $259.85 Take a look at this Scre ...

a method for inserting a space after a certain character, with the exception of when that character is located at the start or end of a line

I've created a regular expression that can modify various patterns like: anything1 * anything2* anything3 anything1* anything2 * anything3 anything1 * anything2 * anything3 anything1*anything2 *anything3 anything1 * anything2 *anything3 anything1*any ...

The findElement method of WebElement is utilized to locate an element within the scope of

In attempt to run my Selenium test, I have implemented the following HTML code: <html> <head></head> <body> <table id="Original"> <tr> <td>Original-11</td> <td>Original-12</td& ...

Unable to fetch any links through the driver.find_elements method using the href attribute

As a newcomer to Python and Selenium WebDriver, my goal is to verify all links on my webpage by checking their HTTP status codes to identify any broken links. The snippet of code I am currently using looks like this... from selenium import webdriver from ...

Managing business logic in an observable callback in Angular with TypeScript - what's the best approach?

Attempting to fetch data and perform a task upon success using an Angular HttpClient call has led me to the following scenario: return this.http.post('api/my-route', model).subscribe( data => ( this.data = data; ...

Error retrieving user by provider account ID using Google and Firebase adapter with Next Auth

Encountering an issue while trying to integrate Google Provider with Firebase Adapter in Next Auth. Upon selecting an account, the following error is displayed: Running Firebase 9 TypeError: client.collection is not a function at getUserByProvider ...

What is the method to obtain an object as the return value from a click function in JavaScript?

I would like to retrieve the cell value from a table by clicking on a button. I have already created a function called getDetail in JavaScript that is implemented on the button, but I am facing difficulty in returning the value from the function. <butto ...