0

Code trials:

img_source = driver.find_element_by_css_selector('#root > div > div > div > div.MainFrameContainer > div > div > div > div > div > div > div.reader-area > div.reader-pages-container > div:nth-child(4) > img.f.e').get_attribute('src')

thumbs = driver.find_element_by_css_selector('div.thumbnail-storage')
driver.execute_script('arguments[0].scrollBy(arguments[0].scrollWidth, 0)', thumbs)
sleep(1)
pages = driver.find_elements_by_css_selector('#root > div > div > div > div.MainFrameContainer > div > div > div > div > div > div > div.reader-scrubber-container > div > div:nth-child(1) > h1 > div.pages-counter > span:nth-child(3)')

Html for image url:

<img crossorigin="anonymous" src="blob:https://1.mysite/7e50ba18-3f0f-4b8d-acff-5684d3d551bc" class="f e" style="width: 2000px; height: 2697px;">

When run bot tell me error:

    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#root > div > div > div > div.MainFrameContainer > div > div > div > div > div > div > div.reader-area > div.reader-pages-container > div:nth-child(4) > img.f.o"}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

1

As per the HTML:

<img crossorigin="anonymous" src="blob:https://1.mysite/7e50ba18-3f0f-4b8d-acff-5684d3d551bc" class="f e" style="width: 2000px; height: 2697px;">

To extract the value of the src attribute you can use either of the following locator strategies:

  • Using css_selector:

    print(driver.find_element_by_css_selector("img[crossorigin='anonymous'][src^='blob']").get_attribute("src"))
    
  • Using xpath:

    print(driver.find_element_by_xpath("//img[@crossorigin='anonymous' and starts-with(@src, 'blob')']").get_attribute("src"))
    

Ideally you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "img[crossorigin='anonymous'][src^='blob']"))).get_attribute("src"))
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//img[@crossorigin='anonymous' and starts-with(@src, 'blob')']"))).get_attribute("src"))
    
  • 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