I’m trying to select an image element using its style selector. I wrote the line of code in Python but I’m having problems translating it to JavaScript. Here’s my attempt so far.
if driver.find_element_by_css_selector("img[style='object-fit: cover;']") is not None:
download_url = driver.find_element_by_css_selector("img[style='object-fit: cover;']").get_attribute('src')
And here is my js attempt.
let imageArr = []
for(let post of posts) {
await page.goto(post)
await page.waitForTimeout(6000)
if (await page.type("img[style='object-fit: cover;']") !== null) {
const image = await page.evaluate(() => {
document.querySelectorAll("img[style='object-fit: cover;']").forEach(img => {
let imageUrl = img.getAttribute('src');
imageArr.push(imageUrl)
})
})
}
}