Is there a way to use Selenium to automate the clicking of two buttons with empty href attributes? Each button has a function name and arguments within the href

Here is the HTML code for both buttons:

<td>
<a href="javascript:abcMy(2310);" class="btn btn-lawa btn-primary btn-primary-lawa">View</a>
</td>


<td>
<a href="javascript:abcMy(2330);" class="btn btn-lawa btn-primary btn-primary-lawa">View</a>
</td>

Answer №1

Utilize xpath to uniquely locate elements based on their index position.

Answer №2

Feel free to try out any of the following xpath expressions

Remember to use indexing once you have completed your selection of xpath

Hint:- Indexing always starts from 1

For example, if you need to click on the second view link button, use the xpath below.

//a[text()='View'][2]

OR

//a[@class='btn btn-lawa btn-primary btn-primary-lawa'][text()='View'][2]

Explanation of xpath:- Utilize the class attribute in conjunction with the text method within the <a> tag.

OR

If you wish to click on the first view link button, you can use the following xpath.

//a[text()='View'][1]

OR

//a[@class='btn btn-lawa btn-primary btn-primary-lawa'][text()='View'][1]

Answer №3

The content is contained within a table. An alternative method to locate it is as follows:

  1. Check the xpath of the table. For example:

.//*[@id='ID']/div[2]/table/tbody/

  1. Navigate to the specific row of the table. If the row number is 2, the xpath would be:

".//*[@id='ID']/div[2]/table/tbody/tr[2]"

  1. Proceed to the cell within that row of the table. If the cell number is 4, the xpath will be:

".//*[@id='ID']/div[2]/table/tbody/tr[2]/td[4]"

  1. Within the [td] tag, you will find your desired element. Lastly, navigate to your element and the xpath would be:

".//*[@id='ID']/div[2]/table/tbody/tr[2]/td[4]/a"

Answer №4

driver3.findElement(By.cssSelector("[href='javascript:abcMy(2330);']")).click();

This code snippet allows you to select the second button on a webpage using the cssSelector method.

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

Exploring the interplay between jQuery functions and the "Class" method in Javascript

Is there a way to reference a parent "class" method in Javascript from a jQuery function? Here's an example scenario: $Object.prototype.TestFunction = function(arg){ alert(arg); } $Object.prototype.foo = function(){ $(something).click(function ...

Having trouble rendering the React app; encountered an error: JSX contents are unterminated

I am currently facing an issue while trying to fetch data from an API in React using Axios. How can I ensure that useEffect functions properly? My objective is to create a page by fetching data from an API in React through Axios. I have designed a compon ...

What could be causing the sudden disappearance of the button?

There is an element with the ID "alpha" that contains the text "Now I'm here...". When the button is clicked, only the text should be removed, not the button itself. <div id="alpha">Now I'm here...</div> <button type="button" oncl ...

Learn how to securely transmit data using basic authentication in Node.js with the node-fetch module

Having trouble with this code. I am facing an issue where a "post" request with basic authentication returns a 200 status, but no response data is received. Surprisingly, when the same code is executed without auth credentials, it works perfectly fine. l ...

"Efficiently setting up individual select functions for each option in a UI select menu

I've integrated UI Selectmenu into my current project UI selectmenu includes a select option that allows for setting select behavior across all selectmenu options, as shown in the code snippet below: $('.anything'). selectmenu({ ...

Error in locating an element using Selenium's xpath with findElement

Recently delved into the world of Selenium for automation testing and have been diligently following a tutorial on udemy. Successfully located the xpath to a navigation bar post login to verify user authentication. It worked flawlessly in the console, but ...

How can I include line breaks using HTML `<br>` tags in a textarea field that is filled with data from a MySQL

Within a modal, I am showcasing a log inside a read-only <textarea> field that contains data fetched from my MySQL database. Below this, there is a writable <textarea> field where users can input updates to the log, which are then added to the ...

Store WhatsApp credentials in a file for easy loading into selenium

from selenium import webdriver from selenium.common.exceptions import NoSuchElementException, TimeoutException driver = webdriver.Firefox(executable_path='/home/geckodriver') driver.get('https://web.whatsapp.com/') # scan ...

Error: Unable to access undefined properties (reading 'url')

I am currently working on creating a drag-and-drop card game and I have encountered an issue with the react-dnd library. When using data from the file, everything works fine, but if I have to fetch the data externally, it throws an error. This problem see ...

Issue with Multiple File Upload Functionality in Dropzone.js + Laravel (Only allowing one file to be uploaded)

Looking for assistance in uploading multiple files using AJAX with Dropzone.js plugin. This is what I have implemented so far - HTML (view)- <div class="dropzone" id="add-slide-image"> </div> JS- Dropzone.autoDiscover = false; var myDropzo ...

Counting checkboxes in jQuery version 1.9

I recently upgraded my website from jQuery 1.6 to jQuery 1.9.1, and now some of my old code is not working as expected. Specifically, I have a piece of code that handles checkboxes in table rows, allowing only up to 5 checkboxes to be active at once and di ...

In search of a new object value to update

Looking to update the value of a specific object key in an array? Here is the code snippet where I want to make this change. I only want to replace the value under Mon, not the entire array length. The key weekday will be provided dynamically. array = [ ...

Parent's hover element

I am currently working with the following loop: <?php if( have_rows('modules') ): $counter = 0; while ( have_rows('modules') ) : the_row(); ?> <div class="col span_4_of_12 <?php if($counter == 0) { ?>firs ...

Choosing premier class and modifying characteristics

Looking for a solution to hide a div without modifying the HTML code directly? By using JQuery, you can manipulate the appearance of elements on a page. While it's possible to select the first instance of a class and retrieve its value, adding an attr ...

Pattern for Ajax callback in Javascript

I'm facing an issue with the code snippet below. var bar = { ajaxcall : function(){ var _obj = {}; $.ajax({ headers: { 'Content-Type': "application/json; charset=utf-8", 'da ...

Dynamically switch between doubling Ajax calls in JavaScript

Encountering an issue with a jQuery click function. Triggering the click event on an HTML button dynamically loads styled checkbox and toggle switches based on their stored on/off state in a database. An additional click function is added to each loaded t ...

Tips for keeping a floating action button visible at the bottom of the screen at all times

I am currently utilizing the Material UI framework. I have a floating action button that I would like to display in a specific position on the page without it moving when scrolling, and I am also wondering if this is a common issue. Below is the code sn ...

Find your favorite artist on Spotify through the search function

Recently, I stumbled upon this intriguing demo showcasing how to search for an artist using the Spotify API. However, despite several attempts, I have been unable to make it function properly. Can anyone provide any tips or guidance on making this work suc ...

Having trouble loading the linked CSS file in the Jade template

My directory structure is organized as follows: --votingApp app.js node_modules public css mystyle.css views test.jade mixins.jade In the file mixins.jade, I have created some general purpose blocks like 'bo ...

Enhancing the "click-to-pause" feature with jQuery Cycle

Is it possible to delay the click-to-pause feature on my slideshow until after the first slide transition? Currently, the slideshow becomes clickable as soon as the DOM is ready, which is too early for my liking. Here is a simplified version of my current ...