[英]How to click on Element in Canvas using Selenium Python
我試圖單擊第一個canvas元素,但是沒有點擊。 我嘗試通過以下方式:
第一種方式
menu = driver.find_element_by_xpath("*//div[@id = 'cy']/div/canvas")
ActionChains(driver).move_to_element(menu).perform()
第二路
driver.find_element_by_xpath("*//div[@id = 'cy']/div/canvas").click()
這是html代碼:
<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>
嘗試move_to_element_with_offset
,它應該為您工作:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.