double click visual element not in html to make textarea appear selenium

Viewed 576

I want to enter text into a textarea. The problem is the textarea is only created and shows up in the html after clicking twice on a visual element in the browser. For this visual element Dubbelklik om je tekst te typen, I cannot find an element in the html that refers to it and perform a double_click(). There are only containers, that either are unclickable elements, or allow clicks, but don't perform an action.

Up until here it works and the visual cue to double click appears slightly below the center:

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

driver = webdriver.Chrome()
driver.get("https://www.hallmark.nl/kaarten/verjaardag-man/")
#wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='https://www.hallmark.nl:443/kaarten/verjaardag-man/grappig-m/make-that-the-cat-wise/happy-bursdeej-to-jou-3415094.aspx']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='https://www.hallmark.nl:443/kaarten/verjaardag-man/grappig-m/hallmark/een-jaguar-voor-je-verjaardag-3346861.aspx']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.ID, "btnShowSizepicker"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Standaard']"))).click()
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'showDesktop')]//button[contains(text(),'Binnenkant')]"))).click()

But from then on I can't seem to find anything to make selenium click on the element. I have tried clicking the things I can locate in the html:

# elem = driver.find_element_by_xpath("//div[contains(@class, 'canvasAnchor')]").click()

This gives an element not interactable error. I have also tried using an offset for a findable element:

elem = driver.find_element_by_class_name("canvas-container")
print(elem.location)
print(elem.size)
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(elem, 0.5*elem.location.get('x'), (0.5*elem.location.get('y'))) #should click in the middle of this container
action.double_click()
action.perform()

But for different elements and values of x and y, I can only get it to do either nothing, or click on the contact sidebar (which highlights the word 'Neem').

If I click twice manually, a textarea appears in the html and I can execute send_keys('hello world')

1 Answers

The element where you have to click is actually canvas, so what you have to do is that move cursor to the position where double click is needed and then click there.

I tried this over your code and worked for me:

from selenium.webdriver.common.action_chains import ActionChains

elem = driver.find_element_by_xpath('//*[@class="canvasWrapper active"]//*[@class="canvas-container"]')
ActionChains(driver).move_to_element_with_offset(elem, 70, 60).double_click().perform()

Note:You may have to wait for the canvas element to load properly. I just tried from prompt.

You can read about this mouse action here.

UPDATE:

I noticed that somehow the double click was behaving as single click for me, so changed to this.

from selenium.webdriver.common.action_chains import ActionChains
import time

elem = driver.find_element_by_xpath('//*[@class="canvasWrapper active"]//*[@class="canvas-container"]')
ActionChains(driver).move_to_element_with_offset(elem, 70, 60).click().perform()
time.sleep(1)
ActionChains(driver).move_to_element_with_offset(elem, 70, 60).click().perform()
Related