我试图右键单击一个元素,然后从列表中选择一个重命名"选项.我已经右键单击"工作了,但是无法从列表中选择选项.引用链接 1 , 2
I am trying to Right click on an element and then select an option "Rename" from the list. I have got "right clicking" working but can't select option from the list. Referred links 1, 2
注1:
1:右键单击显示的菜单选项是本机上下文菜单.因此,它们不会出现在我可以看到的DOM中.
1: On right click the menu options that are visible are native context menus. So, they don't appear in my DOM that I can see.
2:该应用仅在Chrome浏览器中运行(不确定是否是浏览器问题)
2: The App runs only in Chrome browser(not sure if it is a browser issue)
我尝试了以下代码:
browser.actions().mouseMove(elementVar).perform(); browser.actions().click(protractor.Button.RIGHT).click(protractor.Button.ARROW_DOWN).click(protractor.Button.ARROW_DOWN).click(protractor.Button.ARROW_DOWN).perform();请考虑将重命名"作为列表中的第三个选项.
Consider, "Rename" to be the third option in the list.
注2: 如果我只是运行该应用程序,然后从键盘上输入"R",它将选择重命名"选项.但是,当我尝试在测试中运行它时,它没有选择重命名"选项.参见下面我尝试过的代码:
Note 2: If I am just running the app and enter 'R' from my keyboard, it selects the "Rename" option. But when I tried to run it in my test, it doesn't select the "Rename" option. See below code I tried:
browser.actions().mouseMove(elementVar).perform(); browser.actions().click(protractor.Button.ARROW_RIGHT).sendKeys('R',protractor.Key.ENTER).perform();以上代码均无效.让我知道是否需要更多信息.
None of the above code works. Let me know if more information is required.
我猜正在发生以下事情:
I am guessing the following to be happening:
一旦我将鼠标悬停在上方,脚本右键单击",然后显示工具提示".因为右键单击"后显示工具提示",所以我认为菜单列表转到了背景(该列表与工具提示一起仍然可见),这就是为什么向下箭头键不起作用的原因.这可能吗?如果是,我该如何等待工具提示不可见然后右键单击?
once I mouse over, the script "right clicks" and after that the "tooltip" is displayed. Since the "tooltip" is displayed after "right click" I think the menu list goes to the background(the list is still visible along with the tool-tip), which is why the arrow down keys aren't working. Is this possible? If yes, how can I wait for the tooltip to be invisible and then right click?
输入:我试图等待工具提示不可见,然后右键单击,但是"Arrow_down"仍然不起作用.
Input: I tried to wait for tool-tip to be invisible and then right click, but still the "Arrow_down" doesn't work.
右键单击鼠标后,是否可以将菜单列表置于最前面?
重要:
在元素上单击鼠标右键后,我截取了屏幕截图,但该屏幕截图未显示菜单列表".以下是屏幕截图的代码:
I took a screenshot after I right clicked on the element, and the screenshot doesn't show the "menu list". Below is the code for screenshot:
browser.actions().click(protractor.Button.RIGHT).perform() .then(function() { browser.takeScreenshot().then(function(screenShot) { writeScreenShot(screenShot, "image.png"); }); }); //writeScreenShot takes two variables actual screenshot data and the file name. And the screenshot is saved as "image.png"需要做什么?
推荐答案使用XPath解决您的问题
use XPath to solve your problem
browser.actions().mouseMove(target).perform(); browser.actions().click(protractor.Button.RIGHT).perform(); element(by.xpath('//*[@id="context-menu"]/ul/li[1]')).click();在您的情况下,最有可能是"//* [@ id ="context-menu"]/ul/li [3]".
In your case it will be "//*[@id="context-menu"]/ul/li[3]" most probably.
更多推荐
量角器:右键单击时如何从列表中选择一个项目
发布评论