2

I am having trouble selecting from a drop down list (two actually, Season and Date). I can obtain the values which I want to input to the drop down selector, however am unable to understand what I need to do to be able to programmatically select from the dropdown.

This is the website which is of interest: https://dataride.uci.ch/iframe/RankingDetails/1?disciplineId=10&groupId=1&momentId=19264&disciplineSeasonId=19&rankingTypeId=1&categoryId=22&raceTypeId=0

Here is the base code that I am using: (very sorry about the formatting, had trouble with long strings.)

`import requests
 from selenium import webdriver
 from time import sleep
 from bs4 import BeautifulSoup

 url='https://dataride.uci.ch/iframe/RankingDetails/1?disciplineId=10&groupId=1&momentId=19264&disciplineSeasonId=19&rankingTypeId=1&categoryId=22&raceTypeId=0' browser=webdriver.Chrome(executable_path='F:\Anaconda\chromedriver\chromedriver_win32\chromedriver.exe')

 browser.get(url) season_list=browser.find_element_by_id('seasons_listbox').get_attribute('textContent')dates_list=browser.find_element_by_id('dates_listbox').get_attribute('textContent').split('Ranking')[1]

for i in range(0,len(season_list),4):
    year=season_list[i:i+4]
    for j in range(0,len(dates_list),10):
        date=dates_list[j:j+10]
        print('YEAR: ',season_list[i:i+4],' DATE ',dates_list[j:j+10])`

Here is a screenshot of the two menus I would like to be able to iterate through: enter image description here

1 Answer 1

1

Here is the working code. I get the drop down menu using xpath and then use send_keys

from selenium import webdriver
driver = webdriver.Chrome()
url = 'https://dataride.uci.ch/iframe/RankingDetails/1?disciplineId=10&groupId=1&momentId=19264&disciplineSeasonId=19&rankingTypeId=1&categoryId=22&raceTypeId=0'

driver.get(url)
xpath_season = '//*[@id="ranking-details-view"]/div[1]/div/div/div[1]/ul/li[2]/span'
season = driver.find_element_by_xpath(xpath_season)

xpath_date = '//*[@id="ranking-details-view"]/div[1]/div/div/div[1]/ul/li[3]/span'
date = driver.find_element_by_xpath(xpath_date)

season.send_keys('2016')
date.send_keys('31/12/2015')

If you want to select the option from the drop down list then you need to get the whole list.

Sign up to request clarification or add additional context in comments.

2 Comments

Worked like a charm, I greatly appreciate the assistance with this!... I would assume that if I wanted to cycle through all of the pages (they only report 1-50 riders per page) I would just need to apply the same methodology as you have done?
just send different values using send_keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.