ActionChain click() 返回 Web 元素而不是单击

ActionChain click() returning Web Element instead of clicking

我想知道如何使用 Selenium 模拟登录页面上的按钮单击。当我尝试以下操作时,它给我一个错误,指出在列出的坐标 (635, 353) 处按钮不可点击。

browser = webdriver.Chrome()
browser.find_element(By.XPATH, "//*[@id='signin_btn']").click()

当我尝试使用 ActionChain 时,它 returns Web 元素(应该被点击的按钮)而不是点击。

action = ActionChains(browser)
action.click(on_element=browser.find_element(By.XPATH, "//*[@id='signin_btn']"))

我怀疑它 return 是 WebElement 实例而不是 ActionChains 实例。

这是由于方法的签名,允许链接一些动作。这是 click 方法:

def click(self, on_element=None):
    """
    Clicks an element.

    :Args:
     - on_element: The element to click.
       If None, clicks on current mouse position.
    """
    if on_element:
        self.move_to_element(on_element)
    if self._driver.w3c:
        self.w3c_actions.pointer_action.click()
        self.w3c_actions.key_action.pause()
        self.w3c_actions.key_action.pause()
    else:
        self._actions.append(lambda: self._driver.execute(
                             Command.CLICK, {'button': 0}))
    return self 

你可以看到它 return self.

在您调用 perform 之前它不会点击。

action.click(on_element=el).perform()