Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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>
share|improve this question
    
Are you getting any errors? What is happening? Are you sure the canvas is actually clickable? What are you expecting on click? Thanks. – alecxe Jul 26 at 14:45
    
@alecxe nothing is happening when I click on image. Manually it opens a dailog message when clicked – selenium coder Jul 26 at 15:04

1 Answer 1

Try move_to_element_with_offset, it should work for you:

http://selenium.googlecode.com/svn/trunk/docs/api/py/_modules/selenium/webdriver/common/action_chains.html#ActionChains.move_to_element_with_offset

share|improve this answer
    
The problem is that the co-ordinates of <div id= "cy" , <div style and <canvas are same. When I get the co-ordinates of element at id = "cy" it gives me x= 148 and y = 322, and also gives me same co-ordinates for element at div under div id = cy. So it is not taking click. – selenium coder Jul 26 at 11:09
    
Does it work when you do that manually? – automatictester Jul 26 at 11:32
    
yes it works. when I click on Image it opens a small dailog message – selenium coder Jul 26 at 15:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.