Python Selenium,下拉选项元素当前不可见,可能无法操作

Python Selenium, Dropdown Option Element is not currently visible and may not be manipulated

我遇到了这个错误

selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互:元素当前不可见,可能无法操作

对于这一行 //option[. = 'Individual']

dropdown = self.driver.find_element(By.CSS_SELECTOR, "#selectClaimantTypeContainer select")
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//option[. = 'Individual']"))).click()

我已经添加了 WebDriverWait,但错误仍然存​​在?下拉选项通过 ajax.

动态加载

我该如何解决?这是 WebDriverWait

代码的样子
dropdown = self.driver.find_element(By.CSS_SELECTOR, "#selectClaimantTypeContainer select")
dropdown.find_element(By.XPATH, "//option[. = 'Individual']").click()

看起来它是一个 Select 元素。所以你需要 select 想要的 option 按值或按可见文本,如下所示:

dropdown = self.driver.find_element(By.CSS_SELECTOR, "#selectClaimantTypeContainer select")
dropdown.select_by_visible_text('Individual')