在selenium webdriver中使用contextclick

时间:2017-09-28 10:27:09

标签: java selenium selenium-webdriver

我尝试使用selenium webdriver中的ContextClick()方法右键单击元素并从上下文菜单中选择第二个选项。这是我的示例代码。当我执行此右键单击操作不会发生在指定的元素上,也没有错误消息。 我正在使用selenium 3.4,尝试使用firefox和chrome驱动程序。

对此的任何帮助都非常赞赏..!

const count =  MyArray.reduce((count,item)=>{
     Object.keys(item).forEach((val)=>{
       if(item[val].toLowerCase().indexOf('orange') != -1){
         count++;
       }
     })
     return count
    },0)

1 个答案:

答案 0 :(得分:0)

这是Firefox和selenium jar 3.2及以上的已知问题

请参阅此问题链接:

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

当我尝试它时抛出异常

  

线程“main”中的异常   org.openqa.selenium.UnsupportedCommandException:mouseMoveTo

我试过这段代码:

static char arr[UINT_MAX];

我还将您的代码修改为

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();

当这个语句抛出driver.findElement(By.xpath("//input[@value='Google Search']")).click(); 异常,因为它隐藏了,试试这个代码它适用于我

相关问题