Home > Blockchain >  ActionChains double_click() method does not performs the double click using Selenium and Python
ActionChains double_click() method does not performs the double click using Selenium and Python

Time:11-15

I have the following web page

webpage.

I'm trying to double click the "Blocked_IPs" text.

This is the code that interacts with it:

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])

Problem is, it just doesn't seem to double click it. When I do it manually, it works. When I execute the code, it doesn't. There's only one occurance of the word "Blocked_IPs". This is the output in the terminal:

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

Does anyone happen to know why it's not working? How can I test it? Thanks ahead!

CodePudding user response:

You need to add perform() to make all the ActionChains happen as follows:

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

Ideally you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

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

Note: You have to add the following imports :

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
  • Related