I'm trying to get the data from a html table that seems to load data on a table based on the value of dropdown (with a default value). However, when I do the selenium click() on the dropdown, the table values change but the data I get is still from the old page. How do I get the updated values instead? Here, is the code I've tried.
Note: The URL I'm trying for example is this one
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(url) # you can use the url linked above for example
if browser.find_element_by_xpath(
'//a[@id = "user-header-oddsformat-expander"]/span').text != 'IN Odds':
# choose a type of odd that you want from the top dropdown menu
browser.find_element_by_xpath(
'//a[@id = "user-header-oddsformat-expander"]').click()
browser.find_element_by_xpath(
'//ul[@id = "user-header-oddsformat"]/li/a/span[contains(text(), "IN Odds")]').click()
browser.implicitly_wait(10)
table = browser.find_elements_by_css_selector('div#odds-data-table')
for elem in table:
print elem.text
Here, even after performing the click() before dong find_elements...(), I still get the data from the originally loaded table, not the new one. How do I do that?
Wait for "In Odds" to be the dropdown value using text_to_be_present_in_element():
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "http://www.oddsportal.com/soccer/england/premier-league/aston-villa-chelsea-Ea6xur9j/?r=1#over-under;2"
browser = webdriver.Firefox()
browser.implicitly_wait(10)
wait = WebDriverWait(browser, 10)
browser.get(url)
if browser.find_element_by_xpath(
'//a[@id = "user-header-oddsformat-expander"]/span').text != 'IN Odds':
# choose a type of odd that you want from the top dropdown menu
browser.find_element_by_xpath(
'//a[@id = "user-header-oddsformat-expander"]').click()
browser.find_element_by_xpath(
'//ul[@id = "user-header-oddsformat"]/li/a/span[contains(text(), "IN Odds")]').click()
wait.until(EC.text_to_be_present_in_element((By.XPATH, '//a[@id = "user-header-oddsformat-expander"]/span'), "IN Odds"))
table = browser.find_elements_by_css_selector('div#odds-data-table')
for elem in table:
print(elem.text)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With