Is there a way to retrieve the background URL from CSS using Selenium Webdriver?

I am attempting to verify the URL of an image within a div element's background property in the CSS for the webpage. However, when I retrieve the CssValue and display it, it appears to be blank.

The HTML structure for the div is as follows:

<div class="Welcome">

<h3>Welcome</h3>
.......
</div>

Here is the CSS styling for the div:

div.Welcome {
background: rgba(0, 0, 0, 0) url("imageurl") no-repeat scroll center 25px;
float: left;
margin: 50px 20px 50px 150px;
padding-top: 230px;
width: 300px;
}

I have attempted to locate the image URL using the following code:

WebElement WelcomeImg = driver.findElement(By className("Welcome"));

String WelImg = WelcomeImg.getCssValue("background");

Assert.assertTrue(WelImg.contains("imageurl"));

I have also tried using:

("background-url");

Any assistance on this matter would be highly appreciated.

Answer №1

Why not give something new a shot? Experiment with the background image property and update me on how it went.

WebElement BackgroundImg = driver.findElement(By className("Background"));
String ImgURL = BackgroundImg.getCssValue("background-image");
Assert.assertTrue(ImgURL.contains("imageurl"));

Hopefully this can assist you in some way.

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

Styling Fonts in Safari with CSS

Because FixedSys doesn't appear correctly in Chrome or Safari, I switch it to Lucida Console. While this solution works for Chrome, I encounter a problem with Safari. Unless Lucida Console stands alone, the font will not display as desired. If there a ...

I'm attempting to convert an HTML table to a pandas dataframe, but I'm running into an issue where I'm receiving the error message: TypeError: Cannot read object of type 'WebElement'

Trying to save an html table into a pandas dataframe is giving me trouble. I keep getting the error TypeError: Cannot read object of type 'WebElement'. driver.get('web_url') driver.maximize_window() driver.find_element_by_x ...

Is it possible to use a JQuery function after a page redirect has occurred

Take a look at this interesting fiddle! View the Fiddle I am interested in creating links that scroll to different sections of content areas on my site, similar to the footer links in the example. I have been suggested to use Anglers routing system, but ...

Styling the `mat-hint` in Angular Material for large blocks of text

Currently, I am undertaking a project in Angular 9 and utilizing Material design. If you want to view a demo of my work, you can find it here: https://stackblitz.com/edit/mat-hint-styling-issue?file=src/app/app.component.html In my project, I am using in ...

The background image within Bootstrap theme layouts appears to be missing from both the styles and divs

Encountering a peculiar dilemma here. Attempted to apply a background image to a custom style in order to override/extend a bootstrap column style. Additionally, tried embedding a style directly in the div attribute. Strangely, neither method seems to be e ...

retrieve the parent frame's request URL

I am faced with the task of writing a JSP code that retrieves the getRequestURL() of the parent frame (the URL shown in the address bar) from a child frame. However, when I attempt to do this, I only obtain the URL of the child frame. Is there anyone who ...

Display a snippet of each employee's biography along with a "Read More" button that will expand the content using Bootstrap, allowing users to learn more about each team

I have successfully developed a Google App Script that links to a Google Sheet serving as a database. The application iterates through each row, and I showcase each column as part of an employee bio page entry. ex. Picture | Name | Title | Phone | Email ...

Enhancing the pagination look and feel in Laravel 5.1

Is it possible to customize the paginator layout in Laravel 5.1? I am looking to include first and last links along with the default previous and next links. I would like to change the previous and next links to show icons instead of text, while still ma ...

CSS styling failing to meet desired expectations

Two different elements from different panels are using the same CSS styles, but one displays the desired text while the other does not. The CSS file in question is named grid.css. To see the issue firsthand on my live website, please visit: I am uncertai ...

What Is Preventing Fields from Being Filled in the Drop-Down Menu?

Looking to achieve this outcome: https://jsfiddle.net/nstruth/t0dopzav/1/ The issue I'm facing is that the HTML appears correctly when Volvo is selected, but the JavaScript is not functioning as expected. Despite reviewing similar innerHTML JavaScrip ...

Adjust the size of the container DIV based on the content within the child DIV

I have been searching for a solution to my question without success. Here is the issue: I have a DIV that acts as a container for a Post in my project. Inside this post are classes for the poster avatar, name, timestamp, text, and more. The problem arise ...

Extracting athletic information with requests or selenium

I'm attempting to extract data from the following webpage: Here is the code I've created, but it's not functioning as expected: import requests url = "https://www.sofascore.com/betting-tips-today" r = requests.get(url).json() p ...

An animation in CSS where an element moves off the screen to the right in absolute position and then returns from the

I am currently working on a website featuring moving clouds traveling across the screen from left to right. Although I have successfully implemented the animation for the clouds, there is one specific issue that has me stuck. My goal is to display some of ...

Utilizing Selenium webdriver to fetch comments from statuses or photos on a user's Facebook timeline

I am currently utilizing the Selenium Webdriver with Python for a project that involves automating actions on Facebook. I am facing difficulties in figuring out how to select and load comments (represented by a small speech bubble and number) on various ob ...

Is it possible to modify the button icon on hover by utilizing chakra-ui and vanilla-extract?

My stack includes nextjs13, chakra-ui, and vanilla-extract Seeking guidance on how to update both icon and text within a button upon hover, utilizing chakra-ui and vanilla-extract. The current setup of my button is as follows: <Button > <svg wi ...

Using a width of 100% with the display inline-block property does not function as intended

Is there a way to have both a checkbox and text input in one line, with the text input being responsive? I attempted to use display: inline-block, which worked for keeping them in the same line, but I'm having trouble making the text input fill the re ...

Ways to add more spacing between list items without affecting the position of the bottom div

I'm attempting to achieve a layout similar to an Instagram post, where the list expands but does not push the footer down. In my case, adding margin-bottom to the comment class affects the height of the <div class="post-details-container" ...

Clicking on an element in Selenium using PhantomJS with the href attribute set to "#"

Currently working on coding in Python 2.7. I have successfully set up a web crawler that functions perfectly when driven by FireFox, but encounters issues when using PhantomJS. The problem arises when I attempt to click on an element with href="#" The r ...

The rendering of the font appears distinct when viewed on an iPad compared to when displayed

Visit this website. The menu displays correctly on desktop, but on iPads, the font appears larger leading to a line break. Is it because the selected font isn't loading and defaulting to Times New Roman instead? It seems likely since I experience the ...

Toggle the visibility of images with input radio buttons

Explanation I am attempting to display an image and hide the others based on a radio input selection. It works without using label, but when I add label, it does not work properly. The issue may be with eq($(this).index()) as it ends up selecting a differ ...