Providing a parameter to the OnClick function using Selenium

I am currently using Selenium to automate a webpage. There is a clickable text on the page that says "Show More Matches" and it triggers an OnClick function in the backend. By default, clicking on it shows 5 more matches. In the code snippet below, you can see that the argument is set to 5. However, I want to retrieve 20 more matches by clicking on the same text. Currently, I have to manually edit the HTML code and replace the argument with 20 to achieve this. My goal is to accomplish this task using Selenium.

<td colspan="6" class="last lastR">
   <a class="show_more"
      onclick="glib_show_hidden('','h2h_home',5); return false" 
      href="#">
         Show more matches <span class="arrow"></span>
   </a>
</td>

Answer №1

If you need to modify the property of this specific element:

Using JavaScript with Selenium in Java:
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = driver.findElement(element_locator);
js.executeScript("arguments[0].setAttribute('data-ved', 'glib_show_hidden(\\'\\',\\'h2h_home\\',20); return false');",element);

Alternatively, for Python:

element = driver.find_element_by_xpath("your_xpath")
driver.execute_script("arguments[0].setAttribute('data-ved', 'glib_show_hidden(\\'\\',\\'h2h_home\\',20); return false');",element);

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

Utilizing AngularJS to implement a Currency Filter on the output of a personalized filter

I'm currently working on a custom filter that transforms zero values into ' - ' for display purposes. The goal is to display currency formatting for non-zero values. However, I encountered an unexpected token error while trying to implement ...

JavaScript tile mapping not rendering

<html> <head> <title>TileMap</title> <style> #canvas { outline: 1px solid #000; } </style> </head> <body> <canvas id="canvas" height="1000" width="1000"></canvas> <scr ...

"Guidelines for inserting an image from user input into a HTML div

I am trying to dynamically add input file images to separate divs on an HTML page without using get element by class name. Each div should have a unique image associated with it instead of adding the same image to all divs with the same class. Can anyone p ...

What is the reason why sinon stub is unable to replace the actual exports.function?

I have a situation where my controller async function is calling another async exported function. I am looking to test specific results of the dependent function rather than testing the dependency itself. However, when I try to stub the function, it seems ...

Creating a Popup with JS, JQuery, CSS, and HTML

Seeking assistance in creating an HTML, CSS, and JS/jQuery popup. Looking to have a button that reveals a div tag when clicked, which can also be closed. Any quick responses with solutions would be greatly appreciated. Thank you in advance! ...

Arrangement featuring two distinct types of tiles

Looking for a way to achieve this layout using just CSS or a combination of CSS and a little JS. Click on my avatar to see the reference image enlarged =) I've tried using floats and display options but haven't been successful. Take a look at htt ...

AngularJS $http.get('') is throwing an error because some parameters are missing

I am currently working on an application that utilizes OAuth for authentication, but I am facing some issues with passing the URL parameters correctly. Despite trying various methods, my API keeps returning an error stating that the username and password a ...

What methods can I use to insert an array of objects into a Query?

I'm currently trying to understand how I can pass an array of objects into my GraphQL query. The documentation seems a bit confusing on this matter. In my project, I am using Apollo on the frontend, Graphql-yoga on the backend, and Prisma as my databa ...

Problem with UV mapping when adjusting texture size

I am currently working on an application to modify minecraft models. To display the drawn texture mapped on the 3D player model, I am using ThreeJS. However, I'm facing a challenge related to changing the texture size. Initially, the texture is mappe ...

Communicate through Node.js, with messages that multiply based on the total number of users currently in the chat room

Currently, I am working on a project that involves creating a chat application using Node.js. However, I have run into an issue where the message gets repeated for each user in the chat. For example, if there are 4 users in the chat, the message will be di ...

When getStaticPaths and getStaticProps are programmed to deliver results

Seeking assistance with my first attempt at using getStaticPaths and getStaticProps in nextJS as a beginner. Can anyone help me resolve this issue? const datas = [ { id: 1, name: "Banheiro", image: "https://res.cl ...

Being able to simultaneously open multiple pages in new tabs allows for

Is it possible to open a new tab using JavaScript and close the current page at the same time? Here is the code I have tried: <a href="#" onclick="window.open('test_2.php', '_blank'); window.close();">Click here</a> The n ...

The expression req.files consistently comes back as an empty [object]

I have been encountering an issue with saving uploaded files using their original names (with express-fileupload). Whenever I upload a file, it gets saved in the directory as [object Object]. Node: var express = require('express') var app = exp ...

Tips for transitioning from custom CSS to Material UI's CSS in JS

I came across a project where someone implemented components with custom CSS. One interesting thing I noticed was a wrapper component, similar to Material UI's Container or just a simple div with applied styles. export const Container = styled.div` ...

Using React to showcase a base64 image representation

I'm struggling to show an image that has been sent from my Node/Express server to my React application. I've tried looking at solutions on other platforms, but so far nothing has worked for me. Let me outline the steps I have taken: The image is ...

Requiring a condition for each element in an array which is part of an object

Let's discuss a scenario where I have to decide whether to display a block based on a certain condition. Here is an example array structure: const data = [ { name: "item1" , values : [0,0,0,0,0]}, { name: "item2" , values : [0,0,0,0,0]}, { nam ...

A WebDriver.dll encountered an unanticipated issue and threw an uncaught exception of type 'OpenQA.Selenium.WebDriverException'. Further details: an unexpected and unidentified error occurred

In order to verify that I have set up the web driver correctly for more complex applications, I am working on a basic console application using C# with Selenium language bindings and Microsoft Edge. The Selenium Web Driver C# language bindings version 3.0 ...

Maintain loading state in parent component while the child component's react query is still loading

Within my React application, I have a parent component that sends a request to our API. While waiting for the response, a loader is displayed on the page. Once the response is received, I iterate through the data and pass each iteration to a child componen ...

Simulation of N-bodies in three.js

I am attempting to create a project similar to , but I am encountering issues with my system. Can someone assist me? Here is the link to my project: . I believe I may be incorrectly calculating the attraction between each particle. The main problem lies i ...

Implementing Pagination in Vue: How to Make it Work with Response Data

I am looking to integrate pagination from the response data into my existing code, while also incorporating filters. JavaScript var entriesList = new Vue({ el: "#post-list-template", data: { posts: [], categories: [], cu ...