0

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?

1 Answer 1

2

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
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.