【问题标题】:ActionChains double_click() method does not performs the double click using Selenium and PythonActionChains double_click() 方法不使用 Selenium 和 Python 执行双击
【发布时间】:2021-12-26 00:26:36
【问题描述】:

我有以下网页

.

我正在尝试双击“Blocked_IPs”文本。

这是与之交互的代码:

blocked_ips = driver.find_elements_by_xpath('//td[contains(.,"Blocked_IPs")]')
print(len(blocked_ips), blocked_ips)
action = ActionChains(driver)
action.double_click(blocked_ips[0])

问题是,它似乎没有双击它。当我手动执行此操作时,它可以工作。当我执行代码时,它没有。 “Blocked_IPs”一词仅出现一次。这是终端中的输出:

1 [<selenium.webdriver.remote.webelement.WebElement (session="82b277a5f85cbb202f5cd57c0b800f3b", element="530b1a15-a190-401c-8495-921777f8fa84")>]

有没有人碰巧知道它为什么不起作用?我该如何测试它?先谢谢了!

【问题讨论】:

    标签: python selenium selenium-webdriver action double-click


    【解决方案1】:

    您需要添加 perform() 以使所有 ActionChains 发生如下:

    action.double_click(blocked_ips[0]).perform()
    

    理想情况下,您需要为element_to_be_clickable() 诱导WebDriverWait,您可以使用以下Locator Strategy

    ActionChains(driver).double_click(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[contains(.,"Blocked_IPs")]")))).perform()
    

    注意:您必须添加以下导入:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-28
      • 1970-01-01
      • 2017-08-09
      • 2014-09-05
      • 2020-03-18
      • 2013-07-26
      • 1970-01-01
      • 2020-09-22
      相关资源
      最近更新 更多