简体   繁体   English

从浏览器上下文菜单中选择项目

[英]Select item from the browser context menu

We have a Chrome extension which adds telephony functionality to the browser and I am trying to write a test scenario where the user right clicks on a telephone number and then clicks the Dial option from the context menu.我们有一个 Chrome 扩展程序,它向浏览器添加了电话功能,我正在尝试编写一个测试场景,其中用户右键单击电话号码,然后从上下文菜单中单击拨号选项。

I have seen many workarounds for this and used many myself in the past, but in this scenario I really need to click the context menu item.我已经看到了很多解决方法,并且过去我自己也使用过很多,但在这种情况下,我真的需要单击上下文菜单项。 If I try doing a click offset the item under the context menu is clicked instead.如果我尝试单击偏移,则会单击上下文菜单下的项目。

Can a context menu item selection be done through the webdriver?可以通过 webdriver 完成上下文菜单项选择吗?

在此处输入图像描述

var selectButtonElement = WindowsDriver.FindElementByAccessibilityId(SelectButtonAutomationId);

Actions action = new Actions(WindowsDriver);

action.ContextClick(selectButtonElement).SendKeys(OpenQA.Selenium.Keys.Down).SendKeys(OpenQA.Selenium.Keys.Enter).Build().Perform();

You can build an action with the contextClick() :您可以使用contextClick()构建操作:

Actions actions = new Actions(webDriver);        
actions.contextClick().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).perform();

It is in Java but you can easly implement something like this in C#.它在Java中,但您可以在 C# 中轻松实现类似的东西。 It will select something from the context menu, you just need to add some more ARROW_DOWN 's它会从上下文菜单中选择一些东西,你只需要添加更多ARROW_DOWN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM