Hello so given that i have navigated to this site
https://uk.trustpilot.com/categories
I would like to retrieve the headings of each catogory by using inspect element, I noticed that every heading of the catorgories has a h2 tag
My thoughts were to use a EC condition to wait till for the visibility of all elements that have a h2 tag which should return a list containing all h2 tags which i can then just call getattribute(text) on to get the text
def select_catogory(self):
list = self.wait.until(EC.presence_of_all_elements_located((By.TAG_NAME, 'h2')))
print(len(list))
catogories = self.driver.find_elements(By.TAG_NAME,value ="h2")
for cat in catogories:
print(cat.get_attribute('text')
both presence_of_all_elements_located returned nothing and same with find_elements
)
I realised that my main issue was in my loop where i never had a break condition so it was giving a stale element warning, which i thought was caused by this function, Thanks for the help
def select_button_by_name(self, name_of_button: str):
"""
Navigates to the button in question and clicks on it
input: name_of_button (string)
"""
self.wait
buttons_by_href = self.driver.find_elements(By.XPATH,value ="//a[@href]") #finds all the href tags on the webpage
for button in buttons_by_href:
# Matches the attribute text to the provided button string
if button.get_attribute("text") == name_of_button:
#clicks on the button
button.click()
break