What is the problem with locating elements in Selenium with Java?

I've been encountering difficulties in finding elements on a webpage structured like this:

<tr id="filter100" style="...." idx=0
    <td>
       <div onclick=... style=...
         <table dir = "fil">
           <tbody>
             <tr>
              <td>
               <img id="imgFil100_1" src="//path..."
              <td>
               <td>
               <img id="imgFil100_2" src="//path..."
              <td>
              <td>
               <img id="imgFil100_3" src="//path..."
              <td>

Moreover, I have multiple buttons that follow the pattern of "filterXXX". How can I identify and interact with them.

This is the code snippet I came up with:

List<WebElement> lc = driver.findElements(By.cssSelector("table[id*='imgFil']"));
    for (int i = 0; i <= lc.size(); i++) {
     lc.get(i).click();}

By the way, apologies for any language mistakes.

Answer №1

List<WebElement> allRows = driver.findElements(By.cssSelector("table[id*='filter']"));

for (WebElement singleRow : allRows) {
  List<WebElement> images = singleRow.findElements(By.tagName("img"));

  for (WebElement eachImage : images) {
    eachImage.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

Utilizing Python with Selenium to extract comments from YouTube

Currently, I am utilizing Python Selenium to extract comments from YouTube. from selenium import webdriver browser = webdriver.Firefox() browser.get("https://www.youtube.com/watch?v=a6NhKKl-iR0") for elem in browser.find_elements_by_xpath('//body&apo ...

What is the process by which JAVA allows the creation of an object for the onClickListener interface in Android View?

When looking at the code for creating a button event in Java, I noticed something interesting: View.OnClickListener ocl = new View.OnClickListener(); According to Android documentation, OnClickListener is an interface. So how is it possible to create an o ...

CSS animation for horizontal scrolling with sticky positioning is not functioning as intended

I've designed a creative way to achieve infinite horizontal scrolling using CSS animation, and my goal is to make the first element in the list stick in place. Everything works smoothly when I utilize the left property within the @keyframes. However, ...

Troubleshooting: jQuery animation for background-color doesn't function in Internet Explorer

I've been working on a website and I'm trying to create a navigation bar similar to the one found at . My goal is to have the navbar transition from transparent to a colored background as the user scrolls down the page. For this project, I am ut ...

Positioning the comments box on Facebook platform allows users to

Need assistance, I recently integrated the Facebook comments box into my Arabic website, but I am facing an issue where the position of the box keeps moving to the left. Here is an example of my website: Could someone please suggest a solution to fix the ...

Bootstrap form validation solution

Utilizing bootstrap validation to validate a jsp page. The folder structure is as follows: WebContent ├── bootstrap-form-validation ├── js └── pages All three folders are under the web content. If I create another folder called teacher ...

The exception raised by Selenium is a NoSuchElementException

While executing my mobile automation code using Appium, I encountered the following exception: org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide ...

Creating an Interactive Menu System with Nested Options in Angular 2

I have a JSON structure that I need to transform into a menu with sub-menus based on the value of the sub-menu_location field. Here's an example: { "data": [ { "menu_name": "Primary Operations", "enabled": true, "sub-menu_lo ...

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 ...

Iterating over a table and selecting a specific button on the rows that meet a specific condition

I'm having a bit of trouble and would really appreciate your help. I'm attempting to write a script that will scan through this table and delete any row that contains the word "active". The script needs to check every row in the table. The code ...

Unable to process a JSON response received from RestTemplate

While attempting to parse a JSON response from a web service, I encountered an error message stating that the request sent by the client was syntactically incorrect. Despite my efforts to troubleshoot and remove the Results class from the code, the issue p ...

Aligning Divs in a Responsive Browser

In the following illustration, I am facing an issue with my responsive code. I have three sections named square1, 2, and 3, each containing a white div with text on top and an icon positioned absolutely. Everything works fine when the browser width is 920p ...

What could be causing the malfunction of the .setAttribute() and .removeAttribute functions in my JavaScript program?

Below is a flashcard game I have developed: Once a user enters the correct answer in the text box, "Correct!" is expected to be displayed in bold green font. The CSS attributes are then supposed to be removed shortly after. Here is the HTML code for the i ...

Updating the current reply with a fresh one by utilizing a servlet filter in the Spring MVC framework

My goal is to update an existing json response under certain conditions by using filters. I want to retrieve the existing response from the filter, make modifications with new values, and then replace the old response with the updated one. However, current ...

Ways to incorporate a smooth transition between the opened and closed fab functionality

I am currently utilizing VueJS and Vuetify in my project. I have successfully implemented Vuetify's FAB component, which displays a list of fab buttons as demonstrated in the documentation: <div id="fab-button"> <v-speed-dial v-mo ...

Troubleshooting mat-accordion title problem on mobile devices

Despite reading numerous blogs and conducting extensive searches on Google, I am still unable to resolve the CSS issue related to Angular material below. Your assistance in fixing this problem would be greatly appreciated. Desktop view: https://i.stack.im ...

Step-by-step guide for making a CSS triangle design that is compatible across different browsers

Here's a common CSS code for creating a CSS triangle: display: inline-block; vertical-align: middle; content: " "; border-right: 4px solid transparent; border-left: 4px solid transparent; border-top: 6px solid black; width: 0; height: 0; Click here ...

What is the procedure to reduce my final search result by 1?

When the search is triggered, I want to filter the images by name. However, the issue arises when trying to make everything disappear on filter addition. <ul id="list2"> <li class="in2"> An extra number is added ...

Customizing background images for individual web pages

Having some trouble changing the background image on my Squarespace website homepage. After exploring forums and inspecting my website's source code, I tried using the id #collection-51648018e4b0d7daf0a7cece to target just the homepage background but ...

Inserting a border both above and below an element may result in the parent overflowing

I am facing an issue similar to the following: div.parent { height: 100px; padding: 20px; box-sizing: border-box; overflow: auto; } div.parent div.thing { height: 20px; width: 90%; border: 1px solid black; } <div class="parent"> ...