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

How can I wrap content with the <li> element in a cross-browser compatible way?

I am encountering an issue with the dropdown menu on my website located at . When hovering over elements with a dropdown menu, you may notice that some of the items within the dropdown span more than one line and have varying widths. My goal is to adjust ...

Is it possible to use JavaScript to make a CSS animation mimic the behavior of a :hover effect?

My CSS animation looks like this: HTML: <div class="container" id="cont"> <div class="box show"></div> </div> CSS: .container { width: 100vw; height: 100vh; } .box { position: absolute ...

The issue with jspdf is that it is failing to generate PDF documents of

I'm currently developing a resume builder app using ReactJS. One of the functionalities I'm working on is enabling users to download their resumes as PDFs. However, I've encountered an issue with the generated PDFs when using jsPDF. The down ...

What could be causing this Bootstrap column to misbehave?

Why is the content stacking within each list item instead of being on the same line? I've attempted using floating and adjusting the position, but nothing seems to be working. How can I resolve this issue? .icon-left{ float:left; padding: 1 ...

Lock in the top row (header row)

In a node.js application: How can I lock the top row of a table in place, similar to Excel's freeze panes feature? I think this might involve using some CSS styling, but I'm not exactly sure how to achieve it. When I tried using fixed, the entir ...

How to Use the env() Variable in CSS Styling?

Operating on React with Material-UI, my web app features a bottom nav bar. For certain devices like the latest iPad, I must allocate an additional 8 pixels below it to account for the horizontal gray bar that substitutes for a home button: A valuable insi ...

Graph is vanishing while linked

A unique HTML canvas is included in a standalone file called dashboard.html. To display the dashboard on the main homepage (home.html), we utilize ng-view nested within an ng-if directive. Oddly, clicking on the hyperlink "#" from the home page causes th ...

The for loop in Selenium WebDriver seems to be malfunctioning

I am encountering an issue with my page where I need to input scores for 16 different rows that are automatically generated. When I try to insert scores into each row using a for loop, the code works fine for just one row but fails when I attempt to run it ...

What is the best way to incorporate CSS from node_modules into Vite for production?

I have a TypeScript web application where I need to include CSS files from NPM dependencies in index.html. Here is an example of how it is done: <link rel="stylesheet" type="text/css" href="./node_modules/notyf/notyf.min.css&quo ...

Hovering over a td tag and adding a border using CSS can cause the entire table to

While experimenting on a coding platform: <table> <tr> <td class="changeme">something</td> <td>something</td> <td>something</td> <td>something</td> < ...

unable to choose an option if more than one radio button is being used

I am having trouble with two radio buttons that are supposed to select the gender of an applicant and the gender of the applicant's child. Both buttons are not functioning properly. Can someone assist me with this issue? Here is the code I am using: ...

Issue with Material UI Menu positioning incorrectly when button is aligned to the right or left

When looking at the first image, it appears that the material-UI menu position is working correctly. However, when we change the button position to align-right, the menu position shifts slightly to the left, not perfectly aligning with the right side as in ...

Choosing an item from a dropdown menu in C# using Selenium in web assembly is proving to be ineffective

I am currently working on some automated tests using Selenium Web driver. I have been able to write a script that can locate the class, but I am facing difficulties in selecting one of the items from the drop down menu. Here is the script I have so far: ...

Encountering problems when attempting to click a JavaScript button using Python and Selenium

I am attempting to press the "Pickup" button at the provided link : My code is shown below, however it does not take any action until it fails with the following error: element not interactable pickupurl = 'https://firehouse.alohaorderonline.com ...

Zooming in on the background with an animated effect

I'm experimenting with a zoom in animation on a background image for a brief moment. It seems to work initially but then resets itself. To see an example, I've created a jsfiddle link: https://jsfiddle.net/onlinesolution/tk6rcLdx/ Any idea what ...

The navigation bar on the web app is functioning properly on Android devices but experiencing a CSS problem on

My Nextjs web app includes a navbar with a hamburger menu, logo, and avatar. The navbar functions perfectly on desktop in Chrome, Mozilla, Brave (in developer tools mobile mode), and on Android phones using Chrome. However, when accessed from an iPhone X, ...

Tips on renaming multiple JSON field names simultaneously

I have a JSON stored in a hashmap and I am currently using the ObjectMapper to map the JSON. The problem is that I need to change the field names of most of the values. For example: { "field1":"abc", "field2": "xyz"} I want it to look like ...

Maintain parental visibility with children when navigating to a different page

I am currently working on a vertical accordion menu that opens on hover, stays open, and closes when other items are hovered. The great assistance I received from @JDandChips has been instrumental in getting this feature up and running. Now, my main focus ...

Retrieving the background image URL from inline CSS using jQuery

I'm looking for a link similar to url(img/bg/06.jpg), but when using jQuery, I get a longer link like url("file:///D:/WORKING%20FILE/One%20Landing%20Page/version/img/bg/06.jpg") https://i.stack.imgur.com/8WKgv.png Below is the code snippet in questi ...

Struggling to make Selenium function properly in Java

My webdriver was encountering an error that was resolved by adding guava. However, a new issue has arisen: Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException I am currently using selenium-java-2.38.0. I tried downloading a ...