Home > Mobile >  Python selenium if image existing in page return True
Python selenium if image existing in page return True

Time:02-01

I'm trying to do something about live streams, and i wanna use a function who use selenium to find if spesific url or .png file exist on the page or not. If url or .png is on the page that function returns True, else False. Can someone help me to do it ?

CodePudding user response:

How about Beautifulsoup?

parser = BeautifulSoup(driver.page_source, "html.parser")

and then call find_all, if you have an example I can be more specific :)

CodePudding user response:

try:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.google.com/')

def checkString(yourstring):
    if yourstring in driver.page_source:
        return True
    else:
        return False

print(checkString('googlelogo_color_272x92dp.png'))

CodePudding user response:

How about this xpath?

'//img[contains(@src, ".png")]'
  •  Tags:  
  • Related