For instance if i have a webelement and i want to check if it contains h2 tag or not.. is it possible? if yes then how
from selenium import webdriver
import re
import pandas as pd
from bs4 import BeautifulSoup
chrome_path = r"C:\Users\ajite\Desktop\web scraping\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get('....')
header = driver.find_element_by_xpath('/html/body/div[5]/div[2]/div/ol/li[1]/div/div/div[1]/h2')
if header.contains('h2'):
print("successful")
else:
print("unsuccesful")
header variable contains h2 tag but i cannot use header.contains since its a webelement and not a text
Error
Traceback (most recent call last):
File "test2.py", line 11, in <module>
if header.contains('h2'):
AttributeError: 'WebElement' object has no attribute 'contains'