selenium coder
selenium coder

Reputation: 21

How to click on Element in Canvas using Selenium Python

I am trying to click on first canvas element but it is not taking any click. I tried by following ways:

First way

menu = driver.find_element_by_xpath("*//div[@id = 'cy']/div/canvas")
ActionChains(driver).move_to_element(menu).perform()

Second Way

driver.find_element_by_xpath("*//div[@id = 'cy']/div/canvas").click()

Here is the html code:

<div id="cy">
<div style="position: absolute; z-index: 0; overflow: hidden; width: 1029px; height: 130px;">
<canvas style="position: absolute; z-index: 5; width: 1029px; height: 130px;" data-id="layer0-selectbox" width="1029" height="130"></canvas>
<canvas style="position: absolute; z-index: 4; width: 1029px; height: 130px;" data-id="layer1" width="1029" height="130"></canvas>
<canvas style="position: absolute; z-index: 3; width: 1029px; height: 130px;" data-id="layer2-drag" width="1029" height="130"></canvas>
<canvas style="position: absolute; z-index: 2; width: 1029px; height: 130px;" data-id="layer3" width="1029" height="130"></canvas>
<canvas style="position: absolute; z-index: 1; width: 1029px; height: 130px;" data-id="layer4-node" width="1029" height="130"></canvas>
</div>
</div>

Upvotes: 0

Views: 3039

Answers (1)

Related Questions