简体   繁体   中英

How to select a dropdown with optgroup in Selenium?

<select class="ms-crm-SelectBox" sort="ascending" defaultselected="-1" id="advFindE_fieldListFLDCTL" style="" xpath="1">
    <optgroup id="fld" label="Fields">
        <option value="xyz_accountnumber" datatype="nvarchar" maxlength="100" title="Account Number">Account Number</option>
        <option value="xyz_addsource" datatype="nvarchar" maxlength="100" title="Add Source">Add Source</option>
        <option value="xyz_addsourceleadid" datatype="nvarchar" maxlength="100" title="Add Source Lead ID">Add Source Lead ID</option>
    </optgroup>
</select>

I have trying to select Account Number ,I am using python

dropdown_list = Select(self.driver.find_element_by_css_selector('#advFindE_fieldListFLDCTL'))
dropdown_list.select_by_value('xyz_accountnumber')

I am getting the below error

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be m.

Can you help?

This seems to work for me

element = driver.find_element_by_class_name('ms-crm-SelectBox')
element.click()

option = driver.find_element_by_xpath("//option[@value='xyz_addsource']")
option.click()

Is this what you are trying to do?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM