Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98497

Finding an element within an element using Selenium Webdriver

$
0
0

I am scraping a website that has a list of football games generated using JavaScript. I have written the following line that creates a list of all the game elements on the page:

list = browser.find_elements_by_xpath('//*[@data-sportid="1"]')

If I then write

for game in list:
    print game.text

it prints all the text fields contained in each of the games (home team name, away team name, etc.)

However, the loop

for game in list:
    print game.find_element_by_xpath('//*[@class="home-team"]').text

prints the very first home team's name in the page for each iteration of the loop.

It appears that game.find_element_by_xpath is searching the entire page, and not just this game element, and so it keeps returning the first home team name on the page.

How can I search for a child element within each item of the list?

EDIT

Here is the exact page I am working on


Viewing all articles
Browse latest Browse all 98497

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>