简体   繁体   English

在硒webdriver中使用contextclick

[英]using contextclick in selenium webdriver

I'm trying to use ContextClick() method from selenium webdriver to right click on element and select the second option from context menu. 我正在尝试使用Selenium Webdriver中的ContextClick()方法右键单击元素,然后从上下文菜单中选择第二个选项。 this is my sample code here. 这是我的示例代码。 when i execute this right click opetion doesnt happen on the element specified, no error message as well. 当我执行此右键单击操作时,不会在指定的元素上发生操作,也不会出现错误消息。 I'm using selenium 3.4, tried for both firefox and chrome driver. 我正在使用硒3.4,尝试用于Firefox和chrome驱动程序。

Any help on this much appreciated..! 任何帮助对此表示赞赏..!

driver = new FirefoxDriver();
driver.get("http://google.com"); 
driver.findElement(By.name("q")).sendKeys("London");

Actions action = new Actions(driver);
driver.findElement(By.xpath("//input[@value='Google Search']")).click();
action.contextClick(driver.findElement(By.xpath("//a[text()='Sign in']"))).build().perform();

this is known issue of Firefox and selenium jar 3.2 and above 这是Firefox和Selenium jar 3.2及更高版本的已知问题

See this issue links: 看到这个问题的链接:

https://github.com/mozilla/geckodriver/issues/233 https://github.com/SeleniumHQ/selenium/issues/3348 https://github.com/mozilla/geckodriver/issues/233 https://github.com/SeleniumHQ/selenium/issues/3348

When I tried it throw the Exception 当我尝试它抛出异常

Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: mouseMoveTo 线程“主” org.openqa.selenium.UnsupportedCommandException中的异常:mouseMoveTo

I have tried this code: 我已经试过这段代码:

System.setProperty("webdriver.chrome.driver","E:/software and tools/chromedriver_win32/chromedriver.exe");
 WebDriver  driver = new ChromeDriver( );
 driver.get("http://google.com"); 
 driver.manage().window().maximize();
 driver.findElement(By.name("q")).sendKeys("London");
 driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
 WebElement ele= driver.findElement(By.xpath("//a[text()='Sign in']"));
 Actions action = new Actions(driver);
 action.moveToElement(ele);
 action.contextClick(ele).build().perform();

Also I modified your code as 我也将您的代码修改为

driver.findElement(By.xpath("//input[@value='Google Search']")).click();

as this statement throw nosuchelementexception Exception as it is hiding, Try this code it works for me 由于此语句正在隐藏时抛出nosuchelementexception异常,请尝试使用此代码对我nosuchelementexception

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

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