您的页面使用React Select Component。正如小组中其他讨论的那样,您必须像手动步骤一样完全自动化这种情况,
即
- 单击难以处理的元素。
- 等待下拉菜单出现。
- 单击下拉列表中的值。
这里有两种情况
- 无值时选择
- 选择何时有价值。
我假设页面具有与之相似的单个选择框,并且默认情况下未选择性别值。在下面的代码中,我正在选择男性案例。选择男性后,我将其更改为女性。
选择没有价值的下拉菜单
# this is click the div..Select-placeholder element which is intractabledriver.find_element_by_css_selector('.Select--single .Select-placeholder').click()# Then we are waiting for the dropdown value to appearwait = WebDriverWait(driver, 60)male= wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.Select-option#react-select-5--option-0)')))# Click the element male option value of the dropdownmale.click()用值选择下拉列表
# this is click the div.Select-value element which is intractabledriver.find_element_by_css_selector('.Select--single .Select-value').click()female = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.Select-option#react-select-5--option-1)')))# Click the element female option value of the dropdownfemale.click()获取选择的值
selected_value=driver.find_element_by_css_selector('.Select--single .Select-value').text print(selected_value)清除所选值
selected_value=driver.find_element_by_css_selector('.Select--single Select-clear').click()


