0

I have been trying for a long time to get Selenium to select an option from a drop down select field. It appears not to be selecting the element whatsoever. Could the fact that it requires a reload link be causing issues?

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
import csv
import requests
import re

driver2 = webdriver.Chrome()
driver2.get("http://www.squawka.com/match-results")

el = driver2.find_element_by_id('league-filter-list')
for option in el.find_elements_by_tag_name('option'):
    if option.text == 'Football League Championship':
        option.click()
        break

driver2.quit()
  • 1
    Can you post the Source for the dropdown element itself? It'll help a lot of finding some other alternatives to select the dropdown. – Mercfh May 3 '16 at 17:24
  • 2
    paste your HTML code here so that we can help you. – Bharat Mane May 4 '16 at 7:46
1

try this:

el = driver2.find_element_by_id('league-filter-list')
el.select_by_visible_text('Football League Championship')
| improve this answer | |
  • We prefer answers to have context and not be simply code without explanation. – Kate Paulk Oct 31 '16 at 15:01
  • Jose could you elaborate on the difference between this answer and the OP? I think you're correct, but it's taking some heat for being code-only. It's one of those "give a fish, teach to fish" kind of things. – corsiKa Nov 2 '16 at 14:59
1

You're trying to click an invisible element, which won't work.

It's easiest to use the select class.

For an example, see Daniel Abel's answer in this thread: What is the correct way to select an <option> using Selenium's Python WebDriver

| improve this answer | |
0

As a workaround for dropdown menus that dont have data before interaction you could simply click text after clicking on element.

findYourDropdown.Click
findSomeText.Click
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.