How to perform mouse right click in Robot Framework?

落爺英雄遲暮 提交于 2020-01-06 06:46:44

问题


I' writing automated tests using selenium in RIDE. I need somehow to right click element on page and click option from context menu.

Is somewhere any library for Robot Framework which may be helpful to do that? If not, Could you help me how to do that in other way, using existing keywords for example?


回答1:


I found the solution. I wrote an extension to the Selenium2Library:

from robot.api.deco import keyword
from selenium import webdriver
from selenium.webdriver import ActionChains
from Selenium2Library import Selenium2Library

class ExtendedSeleniumLibrary(Selenium2Library):
    @keyword("Right Click Element")
    def Right_Click(self, xpath):
        driver = self._current_browser()

        actionChains = ActionChains(driver)

        element=driver.find_element_by_xpath(str(xpath))

        actionChains.context_click(element).perform()

Now, I'm not using Selenium2Library but my ExtendedSeleniumLibrary with new method in class and it works.




回答2:


Robot tec:

WebElement SighnPad = (appium.findElement(By.id(Lib.getProperty(CONFIG_PATH, "Sighnparent"))).       //parent
                       findElement(By.className(Lib.getProperty(CONFIG_PATH, "sighnchild"))));  //child

SighnPad.click();

Robot rightclick = new Robot();

rightclick.delay(1500);

rightclick.mousePress(InputEvent.BUTTON1_DOWN_MASK);
rightclick.mouseMove(630, 420);
rightclick.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);


来源:https://stackoverflow.com/questions/47174473/how-to-perform-mouse-right-click-in-robot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!