Even if I search, all of them set a value in Select, and it took some time to find it, so I will make a note here as well.
Premise Windows Python 3.8 Selenium is already in use and should be handled by the driver variable
So you need to import the Select class. You can do various things by making the WebElement that references the Select element a Select type.
Detailed explanation for operating the Select element Official website </ b> https://www.selenium.dev/documentation/ja/support_packages/working_with_select_elements/
Get the value selected from the pull-down
from selenium.webdriver.support.select import Select
#Import Select class to work with Select element
AA = driver.find_element_by_id("A") #Get the Select element with ID A
AAA=Select(AA) #Create Select object You can perform various operations from this object.
#The value selected in the pull-down is
print(AAA.first_selected_option.text)
#In case of pull-down that can select multiple, you can get it in the list.
all_selected = AAA.all_selected_options #all_selected is a list.
This is easy
Get the value selected in the pull-down
Dim AA As WebElement 'Declared with WebElement type
’Get the Select element with ID A
Set AA = driver.FindElementById("A").AsSelect.SelectedOption
Debug.Print (A.Text)’The selected value has been output. I was able to
Today's tweet Speaking of which, just getting the values of text boxes and checkboxes It's been a while since I got the Select value by scraping. Recently, the number of requests has increased again, so let's get it quickly. I want more time to think.
Recommended Posts