T
T
temagadfazer2018-09-02 17:06:15
Python
temagadfazer, 2018-09-02 17:06:15

Why can't selenium find the tag?

There is a site https://www.myscore.ru/ . I decided to parse the results of football matches from the site using selenium for educational purposes, but I just can't do everything "beautifully". In the "completed" tab, it turns out to find all the games that are not hidden. In order to open the games of any league, you need to poke on the span, but you can't find it, even though the tag has its own "expand-league" class. 5b8bedfbe5e9b173802672.png
Here is part of the code:

driver.get(url)
    driver.find_element_by_class_name('li2').click()
    ended = driver.find_element_by_class_name('table-main').find_elements_by_class_name('soccer')
    for item in ended:
        try:
            league = item.find_element_by_class_name('expand-league')
            league.click()
            print(league.text)
        except NoSuchElementException:
            print('.NoSuchElementException')
        except WebDriverException:
            print('WebDriverException')
        games = item.find_elements_by_class_name('stage-finished')
        for game in games:
            print(game.text)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery Glukhovtsev, 2018-09-03
@valera-glukhovtsev

The problem is that there are several elements on the page with the stage-finished class (several arrows). Selenium has a FindElements method (in Java, the name may be different in python) that returns an array of web elements, it is better to use it in your implementation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question