-2

I have the following situation

values = driver.find_elements(By.CLASS_NAME, "roulette-history-item__value-textsiwxWvFlm3ohr_UMS23f")

I get list with 260 keys, So far, okay! However, I need this simplified list, with just the text

values = driver.find_elements(By.CLASS_NAME, "roulette-history-item__value-textsiwxWvFlm3ohr_UMS23f").get_attribute("innerHTML")

Is there any possibility to get something like this above? With find_element it works fine. find_elementS not work.

A loop with values[x].text is too slow. I tested it with a simple array, without the ".text" and it's 1000x faster.

2 Answers2

0

Try:

values = driver.find_elements(By.CLASS_NAME, "roulette-history-item__value-textsiwxWvFlm3ohr_UMS23f")
for value in values:
    v = value.get_attribute("innerHTML")
Md. Fazlul Hoque
  • 15,806
  • 5
  • 12
  • 32
0

To extract the innerHTML or the texts from all the matching elements you can use list comprehension and you can use either of the following locator strategies:

  • Using get_attribute("innerHTML"):

    print([my_elem.get_attribute("innerHTML") for my_elem in driver.find_elements(By.CLASS_NAME, "roulette-history-item__value-textsiwxWvFlm3ohr_UMS23f")])
    
  • Using text:

    print([my_elem.text for my_elem in driver.find_elements(By.CLASS_NAME, "roulette-history-item__value-textsiwxWvFlm3ohr_UMS23f")])
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352