ActionChains DOUBLE_CLICK()方法不使用Selify和Python执行双击 [英] ActionChains double_click() method does not performs the double click using Selenium and Python

查看:35
本文介绍了ActionChains DOUBLE_CLICK()方法不使用Selify和Python执行双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下网页

我正在尝试双击";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")>]

有人知道为什么它不工作吗?我怎样才能测试它?提前感谢!

推荐答案

您需要添加perform()以使所有ActionChain如下所示:

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

这篇关于ActionChains DOUBLE_CLICK()方法不使用Selify和Python执行双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆