Creating a CSS list of "background-image" using Java with WebDriver

I'm currently working on compiling a list of all the background-image values to perform assertions on them.

My approach involves creating a parent element and then attempting to gather a list of all the values associated with it.

This is what I have so far:

WebElement Assert_Parent = driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/div"));  
List<WebElement> Assert_children = Assert_Parent.findElements(By.cssSelector("div.contentInner[name='background-image']"));  
System.out.print(Assert_children);

Each photo under this section has its own specific image. Here's the HTML code related to this, which might explain why my current method isn't yielding results as expected.

<div id="contentInner" class="contentInner" style="background-color: transparent;">
...
(HTML code provided in original text)
...
</div>

If you have any insights or suggestions on how to improve my method, please feel free to share. Your input would be greatly appreciated.

Answer №1

//Find elements with partial CSS search using "*"
By regExCss = By.cssSelector("[ng-style*='background-image']");

List<WebElement> items = driver.findElements(regExCss);  
// Loop through each child element and print out a specific attribute

int totalItems = items.size();

for(int index= 0; index<totalItems; index++){
    System.out.print(items.get(index).getAttribute("Class") + "\n");
}

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

Tips for expanding the IntelliSense analysis capacity of large CSS files

My CSS file is quite large at 3.5MB and Visual Studio 2022 doesn't seem to be recognizing it properly, resulting in a lack of class suggestions. Is there a method to enhance IntelliSense analysis limits and enable code completions for such sizable fi ...

Updating Icons on a Jquery Accordion

I need help modifying an icon to change when clicking on a specific section. Currently, I have the functionality set up to change all accordion icons when opening or closing. However, I am struggling to make it so that only the icon of the selected section ...

Search and extract data from a list automatically

My goal is to streamline the search process for player data on a specific website and extract the information from the table of individual players, with names sourced from an Excel spreadsheet. The next step is to incorporate this scraped data into an ex ...

What are the steps to make a List with the mailchimp API version 1.3 in PHP?

I have been searching through the API documentation at but I'm unable to locate the method for creating a new list. Your assistance would be greatly appreciated. ...

Selenium: Automatically setting the referer Header in Selenium

When using Selenium RC with Chrome, I have encountered an issue where each time Selenium opens a new chrome instance, it automatically sets the HTTP referer Header to a specific value. My web application validates the referer to ensure it contains valid l ...

Setting the default font size in CKEditor is a helpful feature that allows you to

I'm struggling to set a default font size for a specific CKEditor Instance. Despite my efforts in researching online, I haven't found a solution that addresses my issue. On a webpage where users can input website content, there are three Editor ...

Having difficulty traversing through URLs using Selenium?

I've been attempting to navigate through the various pages of a website using the Selenium library, but I'm only able to access the home page. Even after revising my code to address this issue, I continue to encounter the error message: InvalidS ...

The flash movie covers part of the menu that is relatively positioned

While designing a website, I encountered an issue with the Flash slider (CU3ER) overlapping the menu bar. Despite trying various z-index configurations to ensure the drop-down menu stays on top, none of them seem to work. Initially, the drop-down menu rem ...

The global CSS styles in Angular are not being applied to other components as expected

Currently utilizing Angular v10, I have a set of CSS styles that are meant to be used across the entire application. To achieve this, I added them to our global styles.css file. However, I'm encountering an issue where the CSS is not being applied to ...

Tips for dividing strings that span multiple lines

If I receive the following as a String: element1#element2#element3#element4 element1#element2#element3#element4 element1#element2#element3#element4 element1#element2#element3#element4 element1#element2#element3#element4 element1#element2#element3#element ...

The image of Picasso successfully uploaded on the second try

Utilizing the Picasso library, I am able to load a Bitmap by providing a URL. Below is an example of my code: MainActivity.java public class MainActivity extends AppCompatActivity{ private String imageUrl = "https://images.unsplash.com/photo-1532793 ...

What is the best way to divide a String array at specific intervals of words?

I am struggling with a seemingly simple concept. My task involves reading a text file using a BufferedReader, and then splitting the string at whitespaces. The challenge is to create a new string array that groups elements into sets of three from the origi ...

What could be causing my label to not align in the center?

I am facing an issue where my labels are not aligning in the center of the window when I click the corresponding button. Instead, they are just appearing on top of the button without being centered and I'm unsure of the reason behind it. import javax ...

Center element horizontally at a specified breakpoint and below

Can I use Bootstrap 4 utilities to horizontally center an element like a <select> within a col at a specific breakpoint and below? I want to achieve this without using custom CSS. For instance, I want to center a <select> at xs and sm breakpoi ...

Why are my custom material UI styles not showing up after the deployment?

I was attempting to customize a material UI element, specifically trying to increase the size of the icon. Below is the style code I used: export const Icon = styled(Box)({ color: "gray", position: "relative", "& ...

Introduce a transition effect to the MUI Chip component to enhance user experience when the Delete Icon

When the delete icon appears, it is recommended that the overall width of the chip increases smoothly rather than instantly. Here is the current code structure: CSS: customChip: { "& svg": { position: "relative", display: &quo ...

Using Python's Selenium to scrape pages that dynamically refresh with JavaScript can often lead to issues when trying to locate elements on the updated

Hello, I'm looking to extract information from a website view image here As you can see, when I navigate to page 2, the URL remains the same. However, when I attempt to locate an element on that page, I encounter this error: Message: no such element: ...

"Obtaining access data by date using Java: A Step-by-Step

SELECT ItemName, SUM(Unit) AS SoldUnit, SUM(Total) AS TotalAmount, SUM(Profit) AS TotalProfit FROM InvoiceTable WHERE DateSO='"+dateTxt.getText()+"' GROUP BY ItemName; I'm encountering an issue with my query: java.sql.SQLException: ...

Is there a way to extract data from the "Request Headers" of a particular request in the network tab using Python?

I'm attempting to retrieve a precise value of a particular request from the network tab using Python. For instance, suppose I aim to extract the value stored in a cookie from one of the GET requests: When I access the network tab, I encounter variou ...

Can the levels of a binary tree be printed on separate lines by utilizing depth-first traversal method?

I am exploring different methods to print each level of a binary tree in separate lines with a complexity of O(n). Is it possible to achieve this using pre-order, in-order, or post-order traversal? I have come up with some code that involves a depth para ...