Home > Software engineering >  How to select a dropdown menu in selenium python
How to select a dropdown menu in selenium python

Time:07-08

I'm working on a personal project, trying to use selenium to web scrape my locals teams results from a website. The site has three drop-down lists, at the moment I'd be happy to just be able to alter one. The code below clicks reject cookies when I enter the page, that's what the WebDriver line does. I'm getting as far as 'dropdown' and then an error that no such element exists. I've tried CSS_SELECTOR, XPATH and all the other options to no avail. I am only new to this so it could be something simple I'm missing but I've read a-lot of the previous forums with similar questions and the answers didn't work for me.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import time

driver = webdriver.Firefox()
driver.get("https://www.leinsterrugby.ie/domestic-rugby/domestic-fixtures-results/")

time.sleep(3)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='onetrust-reject-all-handler']"))).click()
time.sleep(3)

dropdown=Select(driver.find_element(By.XPATH,value='//*[@id="groups_data"]')
time.sleep(5)
dropdown.select_by_value('5756')

driver.quit() # close browser

CodePudding user response:

The element with dropdown options as Men, Schools, Women, Youth is within an leinsterrugby

  • Related