1
votes

I'm trying to select a value from drop down list. I have checked all posts related to it but not able to find solution.

Here is my HTML code for drop down list:

<select class="paginado-select" onchange="javascript:paginadoListado(1);" name="registros_pagina">
<option></option>
<option>25</option>
<option selected="">50</option>
<option>75</option>
<option>100</option>
<option>125</option>
<option>150</option>
<option>175</option>
<option>200</option>
<option>225</option>
<option>250</option>
</select>

I've tried with this code but it doesn't set anything in the variable select.

# third-party imports
from selenium import webdriver

driver = webdriver.Chrome("C:/Users/PycharmProjects/Tennis-Ranking/chromedriver.exe")
driver.get("http://www.rfet.es/clubes/prov/Madrid/28.html")
select = driver.find_element_by_xpath('//*[@id="paginacion-busqueda-abajo"]/form/table/tbody/tr/td[2]/select').click()
print(select)
select.selectByVisibleText('250');

driver.close()

I would like to select the option 250 to show all the clubs in one page avoding to move to all pages of the table in order to use beautifulsoap to catch the html code.

1

1 Answers

0
votes

Try this:

from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time

driver = webdriver.Chrome('C:/Users/PycharmProjects/Tennis-Ranking/chromedriver.exe')
driver.get('http://www.rfet.es/clubes/prov/Madrid/28.html')
time.sleep(1)

selectPageNo = Select(driver.find_element_by_class_name("paginado-select"))
selectPageNo.select_by_visible_text('250')

See also:

What is the correct way to select an using Selenium's Python WebDriver?