Python selenium function return True If image exists in page
Question:
I’m trying to do something with live streams on social media and when someone send a gift to streamer I want to know what gift is that so I need a function which is returns True when the selected gift .png exists in page.
That code part which is I select as a solution work perfectly.
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'))
Answers:
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 🙂
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'))
How about this xpath?
'//img[contains(@src, ".png")]'
I’m trying to do something with live streams on social media and when someone send a gift to streamer I want to know what gift is that so I need a function which is returns True when the selected gift .png exists in page.
That code part which is I select as a solution work perfectly.
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'))
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 🙂
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'))
How about this xpath?
'//img[contains(@src, ".png")]'