在Chrome中从上下文点击菜单中选择选项 [英] Select option from context click menu in Chrome

查看:141
本文介绍了在Chrome中从上下文点击菜单中选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome 47中遇到了一个问题,使用Selenium(WebDriver)2.48.2,ChromeDriver 2.20.353145和Java作为编程语言。我在网上找不到任何解决方案。
我需要从输入中打开浏览器的右键单击菜单(或上下文点击菜单),我可以使用以下代码执行此操作:

I'm facing an issue in Chrome 47, using Selenium (WebDriver) 2.48.2, ChromeDriver 2.20.353145, and Java as programming language. I couldn't find any solutions online. I need to open the "right click menu of browser" (or context click menu) from an input and I could do this using this code:

new Actions(driverExample).contextClick(inputExample).build().perform();

所以下一步:从中选择一个选项。我在网上搜索,它似乎很简单,但事实并非如此。我没有尝试过其他浏览器,但我总是在网上看到很多人在Firefox和Internet Explorer中使用类似的方法做到这一点:

So the next step: select an option from it. I searched online and it seemed simple, but it's not. I didn't try on others browsers, but I always saw online that many people did this in Firefox and Internet Explorer using something like:

new Actions(driverExample).contextClick(inputExample).sendKeys(Keys.ARROW_UP).sendKeys(Keys.ARROW_UP).sendKeys(Keys.RETURN).build().perform();

在这种情况下,我会放两个向上箭头和一个回车,因为我必须选择从底部的第二个选项。无论如何,这似乎适用于Firefox和Internet Explorer中的用户,但不适用于Chrome浏览器,而且我也没有解决这个问题,所以我也没有看到关于这个问题的讨论。那么为什么不给我和其他人在这里最终的解决方案?提前致谢。

In this situation I put two "arrow up" and one "enter", because I have to select the second option from the bottom. Anyway, this seems to work for people in Firefox and Internet Explorer, but not on Chrome and I also saw few discussions about this problem without solution. So why not give to me and the others a final solution here? Thanks in advance.

推荐答案

似乎有问题。它与firefox一起使用,但不与chromedriver一起使用。请在 https://bugs.chromium.org/p/chromedriver/issues/list中提出问题

Seems an issue. It is working with firefox but not with chromedriver. Please raise issue at https://bugs.chromium.org/p/chromedriver/issues/list

示例代码:

Sample Code:

WebDriver driver = new ChromeDriver();      
driver.get("http://www.google.com/");
Actions a = new Actions(driver);

WebElement input = driver.findElement(By.name("q"));
input.sendKeys("test");
a.contextClick(input).sendKeys(Keys.chord(Keys.ARROW_UP,Keys.ARROW_UP,Keys.ARROW_UP,Keys.ARROW_UP,Keys.ENTER)).build().perform();

这篇关于在Chrome中从上下文点击菜单中选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆