How can I choose which button to click in selenium if there are multiple buttons on the page with the same name, value, and id?

This particular button actually opens a popup, even though it is located on the same page.
![click here for image description][1]

I attempted to interact with the element using the following code:

driver.findElement(By.tagName("td")).findElement(By.id("leadCaptureList_leadCaptureList_assignCampaign")).click();

However, I encountered an error message stating "Unable to locate element: {"method":"id","selector":"leadCaptureList_leadCaptureList_assignCampaign"}"

Answer №1

In case the other button is not located within a td element, you can utilize the code provided below.

driver.findElement(By.xpath("//td/input[@id='leadCaptureList_leadCaptureList_assignCampaign']")).click();

Alternatively, if both buttons share the same xpath, you can incorporate an index in the xpath as shown:

driver.findElement(By.xpath("(//td/input[@id='leadCaptureList_leadCaptureList_assignCampaign'])[1]")).click(); //Make sure to replace [1] with the correct index

If the above methods do not yield results (which seem unlikely), it might be necessary to inspect the HTML of the second button to identify any disparities between the two buttons.

Answer №2

Following Husam's advice, remember to include the parent in your selector, like the div that appears.

//let's say the popup div has an id of "popup"

$("#popup #button").click() could be what you're looking for.

I hope this information proves useful.

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 there a way to divide my time during work hours using Javascript?

This is just a simple example. 9.00 - 18.00 I am looking to modify the schedule as follows: 9.00 - 10.00 10.00 - 11.00 11.00 - 12.00 12.00 - 13.00 13.00 - 14.00 14.00 - 15.00 15.00 - 16.00 16.00 - 17.00 17.00 - 18.00 The current code implementation see ...

Delete a filename in Internet Explorer with the power of JavaScript and jQuery

In my attempts to clear the file input field in IE using $('#files').val('');, I found that it was not effective. $('#uploadimgdiv').html(''); var fil1 = document.getElementById("files"); $('#fil1').val(&a ...

Can the state stored in vuex be accessed by nested components?

After reviewing the documentation at: https://vuex.vuejs.org/guide/mutations.html#committing-mutations-in-components and watching the video tutorial here: I'm unsure whether the store is accessible in nested or child components within the parent co ...

ReactJS - Continuous Loop invoking Encapsulated Function

I keep encountering the same issue with an infinite loop in my code, but I can't figure out why. Currently, I am working with reactJS version 16.5.2 The infinite loops tend to occur when you try to use SetState where it is not allowed (such as in th ...

What is the best way to sort a loop and keep the data for future use?

I'm currently in the process of scraping data from Amazon as part of a project I'm working on. So far, I have set up the following workflow: driver = webdriver.Chrome(executable_path=r"C:\Users\chromedriver.exe") driver.maxim ...

Creating a custom Chrome extension with the ability to modify the pop-up window instead of the web page

Is there a way to modify the content inside my extension's pop-up without affecting the web page being viewed by the user? Also, how can I ensure that my dropdown list functions correctly? I have two dropdown lists where selecting an option from the ...

Loop through an object with only one array using JavaScript

I have a specific object structure that I am trying to iterate through in order to find a particular value within the array. For example, I want to check if the user name is equal to user2. While I was able to accomplish this with two separate objects (cre ...

Is the MessageMap format used by Stomp beyond redemption?

When transferring MapMessages from Java to ActiveMQ and then using Stomp in PHP to retrieve them, I encounter an issue with the array structure. The Java message creation code is as follows: MapMessage message = session.createMapMessage(); message.setInt( ...

Tips on capturing JSON data for export and sending it to a specific URL

After implementing the recommended code changes, I still cannot see any updates on the specified WordPress page - . It appears that there may be a login information or other issue preventing me from viewing the changes. Here is the updated code: // New ...

Uncovering a hidden loader within a webpage using the hidden class

Currently, I am working with selenium webdriver 2.53.1 using Java in conjunction with Firefox version 45.0.1. My task involves detecting a hidden loader class on a webpage, but unfortunately, I encountered an error message: The selector provided //[@cla ...

Retrieve a file through a POST request with node.js

Hi everyone, I'm trying to create a "export to excel" functionality in Node.js for a page. By using Chrome DevTools, I discovered that the file is downloaded after a post request, so I need to replicate it. var request = require('request' ...

Protractor's Get Attribute Value function may return null after updating the Chrome version

Having trouble with Get Attribute Value returning null after updating to the latest Chrome version 91.0.4472.77. It was working perfectly before the update. selector.getAttribute('value') => now returns null Does anyone have an alternativ ...

Generic parameter extending multiple types is utilized in a static field

What I have easily: I possess multiple enums that all extend a shared interface: interface CommonMethods { // some methods } enum E1 implements CommonMethods { O1, O2; // impls of interface methods } enum E2 implements CommonMethods { O ...

What could be causing certain link titles to appear outside of my <a> tags?

Check out this jsbin link to see the issue I am facing. I noticed that some of my link titles are appearing outside the anchor tags. Initially, I thought it was because some titles were enclosed in double quotes. I tried creating a function to fix this, b ...

What is the best way for me to grasp the concept and functionality of 'Array.prototype.join'?

When I tried using Array.prototype.join on a multidimensional array, I encountered a surprising result. To investigate further, I looked into the inner workings of Array.prototype.join and found it to be native code. [1,2,3,4,5,6,7,8].join('') [ ...

How can you utilize a previously opened window from another page in JavaScript?

One of my challenges involves managing windows in a JavaScript environment. When I open a child window using window.open("http://foobar","name"), it reuses the same window when opened with the same name, which is exactly what I want. However, if the origi ...

Replacing default hover behavior from an external library

Currently, I am utilizing a JS library that comes with a specific widget. Basically, I have the following list (I removed unnecessary DOM code): <li class="disabled"> When I hover over this list item, it turns into: <li class="disabled state-a ...

Issue with collapsed navbar button functionality in Bootstrap version 5.1.3

Issue with Bootstrap 5 Navbar Collapse Functionality The navbar collapse button is not working on my PC. The button appears but when clicked, the navbar does not show up. Surprisingly, when I test the code on Codeply (without linking to Bootstrap 5 and ot ...

What is the best approach for handling @RequestParam in a JSP file?

Hello there! I have a query regarding the usage of @RequestParam in @RestController. My question is about extracting @RequestParam from the client side. Below is an example of server code using @RestController: @ResponseBody @RequestMapping(method = Reque ...

Issue with Canvas Update in Loop while Using Three.js Library

In the code snippet provided, it takes in a number of scans which is always set to 2880. The canvas is divided into 2880 sectors to cover a full 360°. The code runs a loop from 0 to 2880, rendering colored points in each sector from the center of the canv ...