I'm trying to test a background-image with Selenium. It doesn't have <img>
tag, it have this html code (it is banner from https://openweather.co.uk/products page):
<div class="current-img white-text half-section-right main-section-desktop"></div>
and this CSS styles
This JavaScript code works well in DevTools console:
const image = new Image();
image.src = 'https://openweather.co.uk/themes/openweather_b2b/assets/img/forecast-banner.jpg';
image.onload = function(){
const imageWidth = this.width;
const imageHeight = this.height;
console.log('Width:', imageWidth, 'Height:', imageHeight);
};
But how to implement this JS code to driver.execute_script
and pass imageWidth
and imageHeight
back to Python code?
If I just pass this code into driver.execute_script("here")
and print it - I got None
.
If replace last line with return('Width:', imageWidth, 'Height:', imageHeight);
I got None
too.
And in general - how to return data from driver.execute_script
back to Python correctly?
For example driver.execute_script("return console.log('Hi');")
gives None
too.