1

I don't find an image on page with selenium. My script is in python.

    try:
        is_captcha = driver.find_element_by_css_selector("img[src*='validation']")
        if is_captcha:
            print("CAPTCHA FOUND!")
    except:
        try:
            is_captcha = driver.find_element_by_css_selector("[src*='validation']")
            if is_captcha:
                print("CAPTCHA FOUND!")
        except:
            print ("No catpcha form for {}".format(link_hyip))

The HTML code where my image is :

<td class="menutxt"><img src="?a=show_validation_image&amp;PHPSESSID=u020264onvkgu0fsl9b94lk1v1&amp;rand=1901750303"></td>

I got this error :

no such element: Unable to locate element: {"method":"css selector","selector":"[src*='validation']"}
  (Session info: chrome=76.0.3809.132)

thank for you help !

12
  • 1
    Why are you looking for a css-selector? I think you should use xpath and search the image source... Something like driver.find_element_by_xpath("//img[contains(@src, 'validation')]"). Commented Aug 29, 2019 at 15:03
  • How about XPATH? driver.find_element_by_css_selector("//img[contains(@src, 'a=show_validation')]"). Commented Aug 29, 2019 at 15:03
  • @nostradamus i got this error with the xpath :( no such element: Unable to locate element: {"method":"xpath","selector":"//img[contains(@src, 'validation')]"} Commented Aug 29, 2019 at 15:11
  • Is it possible to share url? Commented Aug 29, 2019 at 15:12
  • whats the step to replicate this? Commented Aug 29, 2019 at 15:15

1 Answer 1

3

Use WebdriverWait and visibility_of_element_located and the below xpath.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get('https://www.lanysoft.biz/?a=support')
try:
  is_captcha =WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,"//form[@name='loginform']//img[contains(@src,'show_validation')]"))) 
  if is_captcha:
    print("CAPTCHA FOUND!")
except:
    print('recapcha not found')
Sign up to request clarification or add additional context in comments.

1 Comment

Ok that's working well if i copy past in new file. I think i have probem in my file or environnement. I'll check and use this code thank you

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.