Why isn't the click function in Java Selenium working as expected?

What could be causing the issue with the click() function not working?

Website:

String startPage = "http://www.domiporta.pl/mieszkanie/sprzedam?Localization=dolno%C5%9Bl%C4%85skie&PageNumber=24&SortingOrder=InsertionDate";

Code:

List<WebElement> RowsMain = driver.findElements(By.className("detail-card__heading"));
for(int i=0;i<RowsMain.size();i++){
    driver.get(startPage);
    List<WebElement> rows = driver.findElements(By.className("detail-card__heading"));
    List<WebElement> cols=new ArrayList<WebElement>();
    cols=rows.get(i).findElements(By.tagName("div"));
    for(WebElement col:cols) {
        col.click();
    }
}

What could be preventing the click functionality from working as expected?

Answer №1

An issue arises when you navigate away from the current page, causing the DOM to be destroyed. The solution is straightforward - simply locate the elements each time you navigate away from the page. Take a look at the code snippet below for reference.

int rowCount = driver.findElements(By.className("detail-card__heading")).size();
for(int i=0; i<rowCount; i++){
    List<WebElement> rows = driver.findElements(By.className("detail-card__heading"));
    int colsCount = rows.get(i).findElements(By.tagName("div")).size();
    for(int j=0;j<colsCount; j++) {
        rows = driver.findElements(By.className("detail-card__heading"));
        List<WebElement>cols = rows.get(i).findElements(By.tagName("div"));
        cols.get(j).click();
        driver.get(startPage);
    }
}

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

Currently, I am utilizing Selenium with Python to update the value of two WebElements. However, I am encountering a limitation where I am only able to update the value for

The snippet below shows the source code of this page. <tr> <th>Model Name<span class="c-c60000 txtNormal">*</span></th> <td><table cellpadding="0" cellspacing="0" border="0"><tr><td> ...

Handling Date Parsing in Gson: Dealing with NumberFormatExceptions

I am new to using Java and Gson, and I have been encountering difficulties when trying to parse date information from the nobelprize.org API. While I have been successful in parsing other data, errors consistently arise whenever dates are included. How can ...

Navigate through a data grid using Selenium browser automation

I am working with a table from the Ontario Government Employee Directory and I am having difficulty finding the xpath to loop through the data. The table does not have an ID. When inspecting the elements, I see the following structure: <table title="r ...

Tips on scraping content with no identifiable attributes in Selenium using Python

Looking to extract electricity prices data from the following website: . When trying to locate the web elements for the date and price, this is the structure: The first date: td class="row-name ng-binding ng-scope" ng-if="tableData.dataType ...

Guidance on invoking a function/method from one class to another in Selenium WebDriver using Java

I need to invoke the login and search methods from two distinct classes into the main class. I have created separate classes for login and search, but when I try to call both methods in the class that contains the main method, I encounter the following err ...

I'm currently working on developing a web scraper using Python and Selenium to extract specific data from a webpage and save it in a CSV file in a structured row and column format

Here lies my code snippet which is using the Dell website here from selenium import webdriver import time from bs4 import BeautifulSoup import csv import tkinter as tk from tkinter import filedialog import re from selenium.webdriver.support import expecte ...

Failing to properly terminate all Selenium browser instances in Python

While utilizing Selenium in Python for web scraping tasks, I encountered a peculiar issue where instances of Edge were being left open in the /tmp/ directory on my Linux system. These lingering folders in /tmp/ had names like:- /tmp/.com.microsoft.Edge.BX4 ...

Encountering an issue when verifying internal links using BeautifulSoup and Selenium

Want to know how to combine absolute and relative urls? Check out this link. Currently, I am trying to validate internal links using BeautifulSoup and Selenium. The script functions properly for full url paths like: <a href="http...."/> ...

What is the best way to choose the ul list item option using Selenium and C#?

Is there a way to select an item from a ul list using Selenium with C# on a web page? While I can access other controls by their IDs, the select control is giving me trouble. Here's what I have tried: https://i.stack.imgur.com/3u6dm.png This is my a ...

Jackson ObjectMapper: Unexpected character '-' while parsing dates

Json: {name:"abc",TxnDateUTC:2015-09-07T21:11:19Z} Java Code: ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROP ...

Ways to enhance and expand lists in Python

Currently, I am scraping the web for search terms. The goal is to discover suggested terms and then find additional suggested terms for each one, which will be added to the original list. Here is my current code: url = ' starting url ' driver.g ...

Utilizing 'and' and 'Or' with XPath in Selenium Webdriver

My goal is to come up with a unique XPath that encompasses both //a[class='btn btn-invisible btn-link routeLink'] and //a[data-route='#Leads']. Here's another example: //div[@class='btn-group'] and //a[@text()='Lead ...

Concerns regarding the prolonged operation of Selenium

For my web scraping needs, I've been utilizing Selenium as a tool because I require access to a page's content after JavaScript has been evaluated. Each of my five EC2 machines is currently running Selenium along with multiple instances of the cu ...

The code seems to be malfunctioning in Selenium 4.2.0 despite my efforts to troubleshoot by uninstalling and reinstalling Selenium as well as Chrome Driver. Interestingly, no error

After updating Selenium to version 4.2.0, my code stopped working: from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service servico = Service(ChromeDriverManager().install ...

"Selenium WebDriver is capable of interacting with ExtJS combo boxes that share the same XPath, IDs, and CSS paths but have dynamically changing IDs. With its functionality, it allows

I'm facing a challenge with testing a web application built on extJS that features multiple drop-down combo boxes. Each box shares the same class name, and their IDs change every time the page reloads. These combo boxes are not your typical drop-down ...

Converting JSON into Java POJO objects with a dynamically generated key

I'm currently in the process of converting JSON to JAVA POJO. The JSON string I'm working with is structured as follows: { "api": { "results": 1, "fixtures": [ { "fixture_id": 38480 ...

Interacting with an iframe element using Selenium in Python

I have a webpage with an iframe embedded, and I'm using Selenium for test automation: <iframe class="wysihtml5-sandbox" security="restricted" allowtransparency="true" frameborder="0" width="0" height="0" marginwidth="0" marginheight="0" style="dis ...

What is the process of retrieving an image file in a Java post API when it is being transmitted as form data through Jquery?

I have encountered an issue with fetching file data in my POST API when utilizing three input file fields in JavaScript. The values are being sent using formdata in jQuery upon clicking the submit button, but I am experiencing difficulties in retrieving th ...

Matching cases for replacements in regular expressions

How can I create a regex pattern to match a repetitive character followed by another character? For example, input strings may look like any of the following: //window[2]//header[@id=\'top\']/div[1]//a[1] //window[2]//header[@id=&bso ...

Having trouble converting complex JSON objects with inner objects into Java objects using Jackson parser

In my Spring project, I encountered an issue while trying to parse JSON data in string format within the controller. Despite extensive research online, I have not been able to find a solution. I am hoping to get help on this platform. The problem lies in ...