pressing a button with the use of Webdriver and javascript

Despite my efforts to find a way to click on a button using webdriver, I have yet to solve the issue. Can someone please assist? Below is the HTML snippet in question:

<b>
<input name="submit" onclick="javascript:document.getElementById('submitClicked').value='Next';return true;" type="submit" tabindex="2" class="-opa-btn-primary nextButton" value="Next" alt="'Next'" id="submitNext">
</b>

I am attempting to click on the "Next" button.

My attempts so far:

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("return document.getElementById('submitClicked').value='Next';return true;");

This approach resulted in an exception stating that document.getElementBy ID returned null.

Next, I tried:

if(driver.findElement(By.Id("submitNext").isEnabled())
    driver.findElement(By.Id("submitNext").click();

Unfortunately, this method also did not work.

Answer №1

Step 1:

Utilizing the provided information, we can assign an ID to the submit button (submitNext).

Step 2:

Create a prototype for a visible function.

public static boolean checkVisibilityByID(String id)

{

try

{

  driver.findElement(By.id(id)).isEnabled();
  return true;

}

catch(Exception e)

{

    e.printStackTrace();
    return false;

}

}

Step 3:

If the element with ID "submitNext" is visible, click on it using driver.findElement(By.Id("submitNext").click();

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

Is it possible to trigger a function in a component using an array populated with pushed objects?

I have an array of text components that are created using the .push() method: handleWordPress = (i) => { this.setState({selectedWord: this.props.navigation.state.params.meanings[i]}); }; render() { const { params } = this.props.navigation.state; va ...

Can someone explain the process of utilizing forEach to add elements to an array using React's useState hook?

I'm attempting to replicate the functionality of the code snippet below in a React environment. Despite several attempts, I have not been able to achieve the same outcome. Old code that worked (non-React) const array = [] res = await getData() res. ...

I encountered a problem with a script where I received the error message: "TypeError: 'FirefoxWebElement' object is not iterable"

I'm encountering an issue when trying to run this script: pic_hrefs = [elem.get_attribute('a href') for elem in hrefs] Traceback (most recent call last): File "IB.py", line 56, in <module> kidCudix.like_photo('comfort&apos ...

The concept of global variables in phpunit_Selenium2 is an essential aspect

In my coding project, I have an array containing names that I utilize to generate random names within a form. The challenge I face is the need to use this array in multiple functions. class TestMyTest extends PHPUnit_Extensions_Selenium2TestCase { public ...

What is the best way to display text in html based on a specific condition being fulfilled in AngularJS?

Is there a way to display text in an HTML page only when a certain condition in an input box is satisfied, and hide it otherwise? I am currently using AngularJS and here is a snippet of my HTML code: <form novalidate="" class="simple-form">conditi ...

An issue has been identified where the Export to Excel and PDF functionality is not functioning properly within a Datatable after applying a

I am using multiple select option filtering with ajax, jQuery, and PHP in a datatable. The records are being filtered correctly, but after changing the select option, the Export to Excel/ PDF functionality is not working properly. Note:- (1) It always do ...

Utilizing Google Maps API v3 to display driving directions on a map, starting with the loading of two positions

Hey there! I've got this cool map that shows two locations with markers and centers between them. Check it out live here: I'm working on integrating it with the Directions service, similar to this demo: https://developers.google.com/maps/documen ...

Is there a way to compare a particular JSON value to the values in an array and determine if they are similar? If so, how can I update the JSON value with the array value

My inventory of wholesalers looks like this: const wholesalers = [ "B536 - T QUALITY LTD", ]; I also have a collection of JSON objects as shown below: { 'Preferred Wholesaler': 'T-Quality' }, { 'Preferred Wholesal ...

Setting up Material UI Icons in your React js project

I've been having trouble installing the Material UI Icons package with these commands: npm install @material-ui/icons npm install @material-ui/icons --force npm i @mui/icons-material @mui/material Error messages keep popping up and I can't see ...

A comprehensive guide on creating translation files using grunt angular-translate from original JSON files containing translations

I have a unique angular application that requires support for multiple languages. To achieve this, I have implemented the angular translate task in the following manner. My goal is to create separate language files which can be loaded later using the useSt ...

Automatically sync textbox width with gridview dimensions

My goal is to dynamically resize a number of textboxes so that they match the width of my gridview's table headers. The gridview will always have the same number of columns, but their widths may vary. However, as shown in the image below, the width va ...

Refreshing Symfony2 values dynamically with ajax without the need for page reload

Let me start by saying that I am not a front-end expert, and this is my first attempt at working with ajax. My goal here is to update and display the new value without having to refresh the entire page. I only want to refresh the input field and its values ...

What is causing compatibility issues between html5lightbox and angular?

After integrating angular.js into my project, I encountered an issue with html5lightbox not working as expected. Instead of opening images and PDF files in a lightbox, clicking on a link takes me to another page. var app = angular.module('MyApp&apos ...

When utilizing the POST method, the information is submitted to the server without being displayed

Why is my POST method not displaying on the webpage when the GET method does, even though I have not created a method for it in my global.js file? Does the GET method automatically come with POST? I specifically want my POST method to be displayed and not ...

Tips for generating rows in an HTML table

I'm attempting to generate a table with 5 rows and 4 columns, displaying increasing multiples of a user-input number. While I can print the numbers successfully, they all appear in one column. I thought breaking up the loops would solve this issue, bu ...

Guide to using the ng-click function in Angular to set focus on the input in the last row of a table

I am in the process of developing a task management application and I am looking to implement a specific feature: Upon clicking 'Add Task', a new row is automatically added to the table (this part has been completed) and the input field within ...

Issue with TypeORM custom repository not successfully overriding the createQueryBuilder function

I have successfully implemented database i18n for TypeORM in theory. Now, I am looking to override built-in repository methods to incorporate i18n by intercepting them and adding a query. However, I am facing difficulties with overriding the createQueryBui ...

How can a controller in AngularJS detect when the back button of the browser is pressed

I've created a browser trivia game where authenticated players can select a game type, triggering a socket.io event in my Node.js server. The view then transitions to a "Searching for game" screen with a loading icon as the server waits for enough pla ...

An unforeseen repetition of jQuery Ajax calls

I'm currently working on an application that utilizes ajax calls to load content. However, I've encountered a situation where an ajax call goes into a loop but seems to end randomly. Below is the code sequence starting from a double click event l ...

Updating @Html.DisplayFor item following a successful ajax request

Attempting to update a value on my view, I seem to have the correct path, but the update only occurs when I reload the entire view. Here is the HTML: <table class="table"> <tr> <th> @Html.DisplayNameFor(model =&g ...