What is the best approach to interact with and click on a link nested within a button using Selenium

Looking for some assistance. How can I successfully click on a button that is nested inside a div? Currently, I am unable to achieve this action with my current code.

Below is the snippet of my code:

> WebElement btn_Submit =
> driver.findElement(By.cssSelector("a[class*='bodylink']"));
>             
>             clickable=isClickable(btn_Submit);
>             if(clickable){
>                 btn_Submit.sendKeys(Keys.ENTER);
> 
>             }

Here is an excerpt from the webpage:

<div id="pagingBody">
<div style="margin-bottom:10px;font-weight:bold;" id="ex-gen3932">100 Total Results</div>
[1 - 50] |
<a id="ex-gen3926" class="bodylink" href="#" onclick="gosearch('PowRan',51); return false;">[51 - 100]</a>
</div>

Answer №1

Assuming you have thoroughly checked for any bugs and confirmed that the element is not null.

Instead of using:

btn_Submit.sendKeys(Keys.ENTER);

Consider using:

btn_Submit.click();

By doing this, it should trigger the onclick event associated with the button.

Answer №2

Not this:

WebElement btn_Submit = driver.findElement(By.cssSelector("a[href*='bodylink']"));

Instead, consider trying:

WebElement btn_Submit = driver.findElement(By.xpath("//div[@id='pagingBody']//following::a[1]));

If necessary, use ExplicitWait like WebDriverWait to ensure the button is clickable before calling the click() method.

Please inform me if this satisfactorily addresses your query.

Answer №3

Here is a possible solution:

WebElement submitButton =
driver.findElement(By.cssSelector("div > a.submit-button"));
submitButton.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

Discover if a website contains an image using Python and Selenium

Can anyone help me figure out how to use a boolean request to determine if there is an image on the following website: or this one: Your assistance would be greatly appreciated. Thank you! ...

Tips for preserving a string in angularJS or Java (and implementing it in an iframe)

My plan involves utilizing a Java web service to fetch the HTML content from a specific URL using Jsoup, and then returning it as a string to the requesting party, which could be an Angular or JS script. I am keen on preserving this content somewhere and l ...

Efficient method for parsing multiple JSON objects simultaneously to create a single aggregated JSON output

When it comes to efficiently parsing and aggregating multiple JSON data sets, the key is to effectively merge them into a final output. Let's consider the following: Json1 : [ { "id":"abc", "name" : "json" }, ... (10k more JSON objects) ] Jso ...

Incorporating fresh CSS styles through Selenium

I am attempting to showcase all the prices available on this page using Selenium and Chrome in order to capture a screenshot. By default, only 3 prices are visible. Is there a way to disable the slick-slider so that all 5 prices can be seen? I have tried r ...

Harvest data from a website with interactive mouseover features

My current challenge involves scraping dynamically generated data from mouseover events. Specifically, I aim to extract information from the Hash Rate Distribution chart found at . The data is displayed when you hover over each circle on the chart. The fo ...

Pandas Read HTML doesn't have the ability to extract information from interactive images

Currently, I am in the process of extracting data from the website located at: The table on this site is displayed as follows: Specifically, my goal is to scrape this table while also capturing the clickable links found under the PRONI REFERENCE column. ...

What is the best way to make an API call with multiple parameters in Android Studio?

Recently, I developed an app that fetches data from an API and displays it in a list. However, I encountered a problem when trying to retrieve JSON data from an API with a nested JSON array. In the first image, everything is straightforward as all the inf ...

Order ArrayList elements based on specified conditions using SQL query or Java

Within my database, I have a table for employees that includes columns such as emp_id, superior_id, and name. I am attempting to create a tree structure using a JavaScript library. Each employee has a superior_id except for the manager. In order to achie ...

Instructions on running Selenium with Chrome using the command `chrome.exe --remote-debugging-port=9222 --user-data-dir='C:\selenium\ChromeProfile'`:

I am currently working on a project that involves making selenium take control of a Chrome instance that contains all my bookmarks and settings. To achieve this, I have created a specific Chrome profile using the following command: chrome.exe --remote-debu ...

Troubles encountered when trying to click the button while web scraping Fidelity.com using Python and Selenium

Currently, I am in the process of developing a Python script with Selenium to extract data from my account on Fidelity.com. While I have been successful in logging in and interacting with certain buttons on the webpage, I am encountering an issue with the ...

Using Selenium to Implement Basic Authentication Through URL

While running my selenium test using chromedriver-2.24, I encountered an issue when trying to access a webpage via basic authentication with the following code: WebDriver driver = ...; driver.get("http://admin:admin@localhost:8080/project/"); I ...

Interfacing with a PHP script hosted on my server through Java programming

In order to securely access my database, I am looking to utilize a PHP script instead of directly accessing it with Java. This way, I can avoid having the username and password for a read-write account stored in my Java code, which could potentially lead t ...

Unable to execute or troubleshoot any test using selenium

Whenever I attempt to run or debug a test from my project's "class library", nothing seems to happen. No matter which test I run, there is no response. view image here ...

Navigating infinite scroll pages with scrapy and selenium: a comprehensive guide

Struggling with using scrapy +selenium to extract data from a webpage that loads content dynamically as we scroll down? Take a look at the code snippet below where I encounter an issue with getting the page source and end up stuck in a loop. import scrap ...

Issue encountered when attempting to select the button

When attempting to click a button, an error is occurring. The Selenium code being used is: WebElement sa = driver.findElement(By.xpath("html/body/div[2]/div/div[7]/div/div/div[2]/div[2]/a[1]/div/div/div[2]")); ((JavascriptExecutor)driver).execut ...

Error retrieving JSON data nested in another object in Android application

I am currently developing an Android app that interacts with a server through API calls and retrieves JSON data. However, I am facing an issue where I can successfully parse the JSON information up to the first array, but encounter an error mentioning that ...

Ways to confirm the absence of a dynamic image on a webpage using the Selenium Python web driver

On a webpage, there are 4 images that load dynamically. These images cannot be clicked and only have the src attribute in the source code. I used XPath to find the URL for each image. How can I determine if a specific image is present or not when the page ...

Looking to pre-load an image before making a getJson call?

I need help with adding a preloading image effect to my getJson call for drop downs using AJAX. Any suggestions? Here is the code snippet I am currently working with: $.getJSON("myAction.do?method=fetchThruAJAX", { TypeNo: $("#Type").val(), ajax ...

Encountering the NoSuchElementException while using Selenium to scrape a website

I am attempting to extract player names and positions from the following URL: Below is the code I have been using: from selenium import webdriver driver = webdriver.PhantomJS() driver.get('https://thedraftnetwork.com/articles/2021-nfl-draft-big-boar ...

Effortlessly handle submissions in your Spring Ajax controller without the need to refresh the

I have integrated Starbox into my Spring page, and I need to find a way to save the user rating to the database without refreshing the page. How can I set up a Spring controller to handle this value without returning a new view? The goal is for the user&ap ...