1

I know there were several examples with selenium option-selecting. Nevertheless, I still cannot select one in one specific website. https://www.gks.ru/dbscripts/munst/munst20/DBInet.cgi I want to choose Excel option in the top-left Select. The HTML is n attachment

enter image description here

I tried approaching the bar this way

for option in el.find_elements(By.TAG_NAME,'option'):
    print(option.text)
    if option.text == 'CSV':
        option.click() # select() in earlier versions of webdriver
        break

I also used find_elements by class and css_selector

Then I used

select = Select(driver.find_element(By.TAG_NAME,'Select'))
select.select_by_visible_text('Excel')

It could not locate the element either

Could anyone please help?

1 Answer 1

3

To select the with text as CSV from the tag using Selenium you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "select.Select[name='Format']"))))
    select.select_by_visible_text("CSV")
    
  • Using XPATH:

    select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@class='Select' and @name='Format']"))))
    select.select_by_visible_text("CSV")
    
  • Note : You have to add the following imports :

    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
    

References

You can find a couple of relevant discussions in:

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

2 Comments

Just adding a point here. It is a drop-down element right so I beleive using presenceOfElement works instead of elementToBeClickable or visibilityOfElement?
Going by the best practices you are totally correct. I'm just over cautious :/

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.