Performing iteration over a list of elements using Java Selenium by targeting

I attempted to iterate through a list on a website. The separate line ID is as follows:

//*[@id="lista-wiersz-74813704"]

The number varies, so I believe I cannot use it.

A different web element is:

<li id="lista-wiersz-74779144" class = "linkDoKarty ogloszenie clearOver wyroznione standard" data-gtm="zajawka" data-pozycja="6" data-punkty-wyroznienia="2" data-ogloszenie="{'id_ogl':'74779144','id_kat':'397','polozenie':'lista'}".</li>

This is my code:

WebElement offerList= driver.findElement(By.className("//@name='[linkDoKarty ogloszenie clearOver wyroznione standard]'"));
    List<WebElement> offerLists=offerList.findElements(By.tagName("li"));
    for (WebElement offer : offerLists) {
        System.out.print("Value: "+offer.getText());
       }

However, my code isn't functioning correctly. The ID "lista wiersz.." is unique in each instance, So I've attempted to use the class but seems like I'm doing it incorrectly.

Answer №1

One positive aspect is that each li element comes with an id featuring a common prefix, which is lista-wiersz-.

You might want to consider making the following change:

List<WebElement> offerLists = offerList.findElements(By.tagName("li"));

to

List<WebElement> offerLists = offerList.findElements(By.xpath("//li[contains(@id, 'lista-wiersz-')]"));

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

Searching for elements using Select Element

Struggling to execute this piece of code due to a null pointer error on the Select element... Check out the snippet of my code below: @FindBy(id="ddCompany") WebElement Select; public void Test(){ driver.findElement(By.id("igtxtdfUsername") ...

List index out of range error occurs in the if-else block when the condition is met

This script retrieves data from Oddsortal website: import pandas as pd from bs4 import BeautifulSoup as bs from selenium import webdriver import threading from multiprocessing.pool import ThreadPool import os import re from math import nan class Driver: ...

Mastering the art of selecting a web element using xpath with Python and Selenium

Struggling with web scraping on a site featuring this specific structure. <div> <div class = “class1” > <div class = “class2” > <div class = “class3” > <div style = “clear: both; ” > </div&g ...

Converting JSON arrays into Python lists

I am encountering difficulties in parsing a JSON array I created into a Python list. Despite my efforts, I have not been successful in achieving this. Is there a way to convert my JSON array into a Python list? The structure of the json data I want to pa ...

Configuring Dash application testing with webdriver-manager by setting the local path for Chromedriver

I am currently exploring testing Dash applications using the method outlined in this guide: However, I have encountered an issue with specifying the path of Chromedriver for the webdriver-manager used in dash testing. Below is a snippet of what I attempt ...

Error: The specified driver file could not be found at /usr/local/bin/geckodriver

I encountered an issue while attempting to run my automated test cases through Jenkins. Operating Server: CentOS 7 java.lang.IllegalStateException: The driver executable does not exist at the specified path: /usr/local/bin/geckodriver ...

What is the best approach for handling empty list items during web data scraping?

I need help with scraping data into a CSV file from a website that lists contact information for professionals in my field. Everything works smoothly until I encounter a page where certain entries are missing specific details. For instance: I am gatherin ...

An error occurred when trying to send an HTTP request to the remote WebDriver server for a URL, resulting in a null response being thrown

https://i.stack.imgur.com/s4RyZ.png Encountering an error when attempting to use EdgeDriver with Selenium. While ChromeDriver runs smoothly, I am required to use Edge for this project. Some sources suggest that the WebDriver version needs to match the Win ...

JMeter's WebDriver's Javascript Interpreter encountering issue with accessing the second tab window

I am attempting to execute a WebDriver Sampler using the given code: var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //WebDriver classes var wait = new support_u ...

Populating AutoCompleteTextView Material dropdown list with Firebase selected value

Currently, I am utilizing the AutoCompleteTextView material drop down list feature to input data into my Firebase database. The process is functioning correctly and accurately capturing the information as intended. Now, I aim to provide my users with the ...

Ways to rerun a test suite in TestNG without relying on a listener

I needed to find a way to re-run an entire TestNG test suite from the test method itself if any of the test cases failed. Is it possible to trigger the complete suite to run using an XML file or within the Test class in the test method? The re-run should i ...

Sometimes the instruments fail to execute the send_keys function sporadically. What is the best way to deal with this

The Issue: While using Appium's python client to input text with the send_keys method on a WebElement, Instruments sometimes refuses to tap certain keys. This becomes problematic, especially during login procedures where reliable typing or setting val ...

Choose an option from the dropdown list

When I visit a certain website, there is a drop-down menu labeled "Best Time to Contact." However, when I attempt to click on it, I am unable to make a selection from the drop-down menu. Can someone provide suggestions on how to resolve this issue? from ...

What is the best way to transfer variables between two Vue files?

How can I transfer a variable between two Vue files? Hello, in my SendCode.vue file, I have a variable named NewEmail that I would like to use in another file called changePass.vue. Is there any way to do this? Can someone offer assistance? Thank you</p ...

Incorporating a File Attachment within a JSON Structure

Can a file attachment be included in a JSON Object? I am working on an HTML Form with text field inputs and a file attachment, and I would like to send all this form data (including the file attachment) as a JSON Object to the server. Are there any specif ...

The functionality of preserver-order=true is not supported in Selenium Grid

@BeforeTest @Parameters({"selenium.host", "selenium.port", "selenium.browser", "selenium.url" }) public void startServer(String host, String port, String browser, String url) throws Exception { selenium = new DefaultSelenium(host, Integer.par ...

Cycling through a lineup of proxy servers sequentially from 0 to 10

When working on my Python script, I need to input 3 pieces of data named A, B, and C. To make this more efficient, I am looking to organize the data into arrays such as arrayA = [A1, A2 ... A10], arrayB, and arrayC. Each array will contain different variat ...

Using Variables and jQuery: Capturing Values and Putting Them to Use (Part Three)

Hey everyone, I recently posted a question about variables and jquery: how to capture value and use them (part 3). You can also find related questions about variables and jquery: part 1 and part 2. In my project, I needed to: 1. Capture a value from an ul ...

Hold off until the specified text appears in the text box

How can we use WebDriver to wait until text appears in a text field? I am dealing with a kendo text field where the values are fetched from a database, so there is a delay before they appear. I need to ensure the values have loaded before moving forward. ...

Unable to close Chrome driver following completion of capybara test

Currently, I am utilizing capybara 2.1.0 along with the default selenium webdriver, minitest, and test::unit. For certain tests that require the use of the .hover method, I switch to the Chrome webdriver. However, after running these tests using Chrome, I ...