0

Every time I try to get the aria label attribute, I've run into this issue before and the question on here addressing it doesn't help at all. I've tried sleep, and list comprehensions (I honestly don't know why that would make it work), but that's where I'm at right now and my brain is jelly :). Can't use xpath if that's what you want to suggest btw

messages = driver.find_elements_by_class_name('DMBLb')

buttons = message.find_elements_by_class_name('wpO6b')

for button in buttons:
   option_buttons = button.get_attribute('aria-label') 
   print(option_buttons) # returns none

BuddyPal
  • 61
  • 1
  • 6

2 Answers2

0

As per your question and the HTML you have shared it seems that the element is a React element, so to retrieve the attribute aria-label you have to induve WebDriverWait for the desired element to be visible and you can use the following solution:

 print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "element_xpath_you_found"))).get_attribute("aria-label"))

reference

Erkin
  • 96
  • 1
  • 5
0

Try to wait for all elements in the list. For this you will need to import some selenium modules:

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

wait = WebDriverWait(driver, 30)
wait.until(EC.visibility_of_all_elements_located(SelectBy.CLASS_NAME("wpO6b")))

buttons = message.find_elements_by_class_name('wpO6b')

for button in buttons:
   option_buttons = button.get_attribute('aria-label') 

Also, what are you trying to print? Try option_buttons.text

vitaliis
  • 4,082
  • 5
  • 18
  • 40