0

I'm new to selenium and facing issue while selecting an option from the dropdown.

HTML Code:

<select id="fileselection" class="selectpicker show-menu-arrow" name="fileselection" onchange="function1('SELECTEDFILES', 'True')" multiple="" data-width="100%" data-style="btn-info" data-action-box="true" data-live-search="true" data-size="5" tabindex="-98">
    <option value="URL_OF_FILE_1">
       Filename_1.zip
    </option>
    <option value="URL_OF_FILE_2">
       Filename_2.zip
    </option>
</select>

URL also contains the filename

Example:

www.yahoo.com/Filename_1.zip

www.yahoo.com/Filename_2.zip

My code:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='fileselection']//option[contains(.,'Filename_1.zip')]")))
ele = driver.find_element_by_xpath("//select[@id='fileselection']//option[contains(.,'Filename_1.zip')]")
ele.click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='fileselection']//option[@value='URL_OF_FILE_1')]")))
ele = driver.find_element_by_xpath("//select[@id='fileselection']//option[@value='URL_OF_FILE_1')]")
ele.click()

I'm getting the error at the last step(ele.click()). Wait and find element steps are working fine.

Element <option> could not be scrolled into view

Thanks!

Shikhar
  • 93
  • 7
  • Does this answer your question? [How to select a drop-down menu value with Selenium using Python?](https://stackoverflow.com/questions/7867537/how-to-select-a-drop-down-menu-value-with-selenium-using-python) – DeadSec Mar 19 '21 at 11:20
  • @DeadSec - I have tried every single solution provided in the link you've shared. Code works fine till the time it encounters a click() or select(). Tried using select_by_index(), visible_text(), by_value(). No luck, not sure what exactly is happening. – Shikhar Mar 19 '21 at 12:19
  • Try opening the dropdown first clicking in the select. – DeadSec Mar 19 '21 at 13:08
  • @DeadSec Could you please share any answer or reference link. Thanks for your help! – Shikhar Mar 19 '21 at 13:51
  • driver.find_element_by_xpath("//select[@id='fileselection']").click() – DeadSec Mar 19 '21 at 14:03
  • If you want i can help you in a faster way then via StackOverflow in discord if you want: https://discord.gg/vHQxm7AK – DeadSec Mar 19 '21 at 14:03
  • Getting the below error while using the above solution `Message: Element – Shikhar Mar 19 '21 at 14:17
  • Use webdriver wait to wait until the element is visible – DeadSec Mar 20 '21 at 15:45
  • Below code solved my problem ```ActionChains(driver).click(element).send_keys(Filename_1.zip).send_keys(Keys.ENTER).perform()``` – Shikhar Mar 21 '21 at 18:09

0 Answers0