0

I want to select all the options under the 'select tag'. Not in a for loop but all of them together.

I know how to select one option only.

This is the image of the table:

enter image description here

Code sample:

enter image description here

enter image description here

2 Answers2

0

Dear, please confirm what you want. select one or select all at a time. If you select one option only then you will follow this link:

from selenium.webdriver.support.select import Select
from selenium import webdriver 

driver = [please input here browser path]
driver.get('https://mdbootstrap.com/docs/jquery/forms/multiselect/')
select = Select(driver.find_element_by_class_name('custom-select'))
select.select_by_index(2)

NOTE: I am really sorry that i did not understand your question correctly

Munna
  • 19
  • 2
0

Here is the option to select all. I have mentioned 3 methods of identifying options. you can use any one to do that.

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select

driver.get("https://mdbootstrap.com/docs/jquery/forms/multiselect/")

time.sleep(5)

select = Select(driver.find_element_by_xpath("//select[@class='custom-select browser-default']"))

for x in driver.find_elements_by_xpath("//select[@class='custom-select browser-default']/option"):
    select.select_by_visible_text("One")
    select.select_by_index(2)
    select.select_by_value("3")
Deepak Kumar
  • 106
  • 7