Python Selenium,Dropdown Option元素当前不可见,可能无法操作



我收到这个错误

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

对于这条带有//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元素。因此,您需要通过值或可见文本选择所需的option,如下所示:

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

最新更新