H
H
haniaman2020-09-10 14:23:51
Python
haniaman, 2020-09-10 14:23:51

How to compare with child element class?

Hello, there is a rublix.best site, and in the Wheel section (prnt.sc/ueuzz3). There is a column with the history of games (the latter is added to the top). It is necessary for me that depending on what color of the last game, this or that value is displayed in the console, for example, if it is gray, then the print ('GREY') function is executed. I tried to find the entire list by find_element_by_xpath, then assigned it to the all_games variable, and then tried to do it by the class of the child div.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("https://rublix.best/")

time.sleep(35)
wheel = driver.find_element_by_xpath("/html/body/div[1]/div[1]/nav/ul[1]/li[2]/a").click()

while True:
    all_games = driver.find_elements_by_xpath("/html/body/div[1]/div[2]/div[6]/div[1]/div[3]/div")

    if all_games[0].find_element_by_class_name('lggr'):
        print('GREEN')
    if all_games[0].find_element_by_class_name('lgg'):
        print('GREY')
    if all_games[0].find_element_by_class_name('lgb'):
        print('BLUE')
    if all_games[0].find_element_by_class_name('lgr'):
        print('RED')


But I just worked if in turn and it turned out like

this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-09-10
@haniaman

print(driver.find_elements_by_xpath("/html/body/div[1]/div[2]/div[6]/div[1]/div[3]/div")[0].get_attribute('innerHTML'))

Learn

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question