-1

HTML:

<div class="__section-image" style="background-image: url(&quot;/img/all/05_element/continentImg/1.png&quot;);"></div>

at this html part how can I locate the background-image?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Froxy
  • 9
  • 3

1 Answers1

1

To get the background image you need to use value_of_css_property(property_name) method and inducing WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    import re
    
    my_property = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div[class='__section-image']"))).value_of_css_property("background-image")
    print(re.split('[()]',my_property)[1])
    
  • Using XPATH:

    import re
    
    my_property = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='__section-image']"))).value_of_css_property("background-image")
    print(re.split('[()]',my_property)[1])
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352