首页 > 解决方案 > 一个接一个地触发点击功能(在模态中)

问题描述

我正在尝试以下内容;它因错误“ Message: element not intractable”而失败。大概是因为 Python 正试图同时解雇它们。

第一个有效。但是,第二个失败了。我只是尝试sleep在两者之间使用implicity_wait。场景是一个接一个的模态对话框。单击第一个“按钮”,第二个模式显示(基本上是确认屏幕)>不会单击该按钮。

    self.driver.find_element_by_css_selector("#publishButton").click()
    self.driver.implicitly_wait(4)
    self.driver.find_element_by_css_selector(".btn-primary").click()

这是标记;我试图访问的第二个按钮。

<button class="btn btn-mini btn-primary" ng-click="save();">Save As Pending</button>

标签: pythonselenium

解决方案


尝试 WebDriverWait 和第二个按钮的可见性。

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-mini.btn-primary"))).click()

您需要具有以下导入。

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

推荐阅读