How do I verify background image/color of a web page?

Hi, I apologize if this was asked before, but i can’t seem to find any previous post regarding this issue. I was wondering if it’s possible to verify an image and/or color being used in the background of a webpage. If so, how do I go about calling the background as an object? Any method is acceptable although I assume there might be a way to do it in CSS method. If possible, can someone please provide an example. Thanks

Calling out to @Russ_Thomas, since I see CSS stuffs.

hi,

with Selenium here is something

The CSS background property is a compound property - that’s to say, it has subproperties, properties of its own.

The following code will retrieve the CSS background-color of the HTML <body> element:

String js = 'return document.querySelector("body").style.backgroundColor;'
String bgColor = WebUI.executeJavaScript(js, null)

The CSS background property is documented here:

hi,
also this will work
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.support.Color;


String baseUrl = 'https://katalon-demo-cura.herokuapp.com/'

WebDriver driver = new ChromeDriver()

driver.get(baseUrl)

String color = driver.findElement(By.xpath("//*[@id='btn-make-appointment']")).getCssValue("color");
System.out.println(color);
String hex = Color.fromString(color).asHex();
System.out.println(hex);

Thanks I think this works. For me I had to set the driver path in order for this to work. In case someone needs this.


import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.support.Color;

String baseUrl = ‘https://katalon-demo-cura.herokuapp.com/

WebDriver driver = new ChromeDriver()

driver.get(baseUrl)

System.setProperty(“webdriver.chrome.driver”,“C:\YourPath\chromedriver.exe”)
String color = driver.findElement(By.xpath("//*[@id=‘btn-make-appointment’]")).getCssValue(“color”);
System.out.println(color);
String hex = Color.fromString(color).asHex();
System.out.println(hex);


You only need to do this if you instantiate your own driver. You don’t need to do this if you just grab the webdriver that Katalon is using, i.e.:

WebDriver driver = DriverFactory().getWebDriver()
.
.
.

Hope this simplifies things a bit.