1

I try to select the value "Ukrainian Division" in the dropdown box of the following site:

https://www.cyberarena.live/schedule-efootball

with the following code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from webdriver_manager.chrome import ChromeDriverManager
import time

if __name__ == '__main__':
  WAIT = 3
  options = Options()
  options.add_experimental_option ('excludeSwitches', ['enable-logging'])
  options.add_argument("start-maximized")
  options.add_argument('window-size=1920x1080')                               
  options.add_argument('--no-sandbox')
  options.add_argument('--disable-gpu')  
  srv=Service(ChromeDriverManager().install())
  driver = webdriver.Chrome (service=srv, options=options)    
  link = f"https://www.cyberarena.live/schedule-efootball" 
  driver.get (link)  

  time.sleep(WAIT)     
  select = Select(driver.find_elements(By.XPATH,"//select")[1])
  select.select_by_visible_text('Ukrainian Division')    
  # select.select_by_value("1")
  input("Press!")  
  driver.quit()

But unfortunately, nothing happens - the options are not selected with this code. I also tried it with select_by_value with this line

select.select_by_value("1")

instead of

select.select_by_visible_text('Ukrainian Division')  

but this doesn´t work either.

How can I select this option from the dropdown box?

1 Answer 1

1

I tried ypur code and I also could not use Selenium Select object there. I don't know why. But we still can do that directly, with regular Selenium commands.
The following code is working:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)

url = 'https://www.cyberarena.live/schedule-efootball'
driver.get(url)
wait = WebDriverWait(driver, 20)

wait.until(EC.element_to_be_clickable((By.XPATH, "//select[contains(.,'Division')]"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[contains(text(),'Ukrainian')]"))).click()

The result is:

enter image description here

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

2 Comments

Thanks a lot again - works great. Only for clarificaton - with this //select[contains(.,'Division')] xpath-selector you get the select-element where some of their childs have "Division" in it. Correct?
Right. As you already know there are 2 select elements there, so I used some child text to locate it instead of 2 index you used. Indexation in normally less stable than internal child property. And you are welcome again :)

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.