How to use Select Option to print out values for is_multiple, first_selected_option, all_selected_options and options (All options)

  Kiến thức lập trình

Trying to print out results for is_multiple, first_selected_option, all_selected_options and options (All options)

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome()                       #Downloads Chrome Driver & opens a Chrome Session
driver.get("https://demo.guru99.com/selenium/newtours/reservation.php")
toPort = Select(driver.find_element(By.NAME, 'toPort'))

#Select by index
toPort.select_by_index(4)

#option_list = toPort.options 
   
# Purpose: To find out if it's a Multiple selection 
print('To Port isMultiple(): Expected= False, Actual=', toPort.is_multiple()) 

# Purpose: Get 'first selected option'....'Select.first_selected_option'???? Expected: Paris
print("First Selected Option: Expected= Paris, Actual=", toPort.first_selected_option())

# Purpose: Get 'all selected options'....'Select.all_selected_options'????
print("All Selected Options: Expected= Paris Actual=", toPort.all_selected_options())

# Purpose: 'All Possible Options'....'Select.options'????
print("All Possible Options: Expected= List returned, Actual=", toPort.options)

driver.quit()

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT