1

I want to get the src attribute of some elements like this:

    <div class="product-tile restored" data-v-27bc931c=""><a href="/p/apple-iphone-11-pro/R1NFM0000000T7"
        class="product-tile__link">
        <div class="product-tile__image product-img-front">
            <img alt="Apple  iPhone 11 Pro"
                data-src="/img?width=300&amp;height=300&amp;action=resize&amp;url=/catalog/product/6/f/6f7466aef1ae14ee4fe9764531ef69a1.jpg"
                src="/img?width=300&amp;height=300&amp;action=resize&amp;url=/catalog/product/6/f/6f7466aef1ae14ee4fe9764531ef69a1.jpg"
                lazy="loaded">
            <div class="image-loading"></div>
            <!---->
        </div>
        <div class="product-tile__description">
            <div title=" iPhone 11 Pro" class="product-tile__name"><span class="product-tile__brand">Apple</span> iPhone
                11 Pro
            </div>
            <!---->
        </div>
        <div class="product-tile__footer">
            <div class="product-tile__condition">
                <div>Various conditions<span class="colors"><span class="dot">•</span>4 Colors</span></div>
            </div>
            <div class="product-tile__price">
                <div class="price" data-v-678b2a80="">
                    <div class="current-price" data-v-678b2a80="">
                        <div class="from" data-v-678b2a80="">from</div>
                        <div data-testid="productPrice" class="amount" data-v-678b2a80="">
                            $647.00
                        </div>
                    </div>
                    <div data-v-678b2a80=""><span class="amount amount--del" data-v-678b2a80="">$1049.00</span> <span
                            class="amount amount--save" data-v-678b2a80="">Save
                            $402.00</span></div>
                </div>
            </div>
        </div>
        <div class="product-tile__loading"></div>
    </a>
    <!---->
</div>

I'm using driver.FindElement(By.CssSelector("img[lazy='loaded")) but the problem is that this attribute can also be loading. When I try driver.FindElement(By.TagName("img")) that doesn't work.

I don't want to use Try and Catch. How to can I get the src? Here is the website that i want to scrape

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
pupy frias
  • 109
  • 3
  • 9

1 Answers1

1

To consider both the cases, when value of lazy attribute is loaded and loading, you can use comma seperated values for the and use the following locator strategy:

driver.FindElement(By.CssSelector("img[lazy='loaded'], img[lazy='loading']"))

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352