如何用硒记录细胞景观.js元素的右键单击?



我正在为一个包含细胞景观.js树的网站编写硒(python(测试。我正在尝试在细胞景观的一个元素(节点(上记录一个 ritgh 单击操作,但我找不到在 python 中执行此操作的方法,当我使用 selenium IDE 在浏览器中创建测试时,不会记录对 Cytoscape 的操作。

要在 Python 中执行右键单击,您需要使用ActionChains中的context_click操作。

from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
actionChains = ActionChains(driver)
web_element_to_click = driver.find_element_by_id("someId")
actionChains.context_click(web_element_to_click).perform()

如果找不到要单击的 Web 元素(由于动态浏览器页面(,则可能需要按坐标单击,方法是将鼠标移动到坐标,然后执行context_click

# move_by_offset moves your mouse from its last known location to given x,y offset
ActionChains(driver).move_by_offset(x,y).context_click().perform()

最新更新