如何使用Selenium中的optgroup选择下拉列表?

2024-10-01 15:30:38 发布

您现在位置:Python中文网/ 问答频道 /正文

<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>

我正在尝试选择帐号,我正在使用python

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

我得到下面的错误

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

你能帮忙吗


Tags: addidsourcetitlevaluenotselectoption
1条回答
网友
1楼 · 发布于 2024-10-01 15:30:38

这似乎对我有用

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

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

这就是你想做的吗

相关问题 更多 >

    热门问题