代码之家  ›  专栏  ›  技术社区  ›  Steve Staple

例外:键向下/向上事件仅对修改键有意义

  •  0
  • Steve Staple  · 技术社区  · 7 年前

    我正在使用JavaSelee,使用Firefox驱动程序进行测试。

    我想将ctrl+发送到我的Firefox浏览器。

    这是我的代码:

        Common.myPrint(thisClass + " *** zoomOut ***");
        Actions actionObject = new Actions(driver);
        try {
            actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.CONTROL).keyUp(Keys.SUBTRACT).perform();
    
            // reset this counter - basis for request counter
    
            global.variables.dataTotalCount = 0;
    
            return true;
        } catch (Exception e) {
            int errorCode = 1525182195;
            System.err.println(thisClass + " error code: " + errorCode + " Exception: " + e.getMessage());
            return false;
        }
    

    我收到这个错误消息:异常:键关闭/向上事件只对修改键有意义。

    这一切都很好,但如何发送ctrl&-(以减小字体大小)

    2 回复  |  直到 7 年前
        1
  •  1
  •   Prany    7 年前

    试弦法

    String selectkeys= Keys.chord(Keys.CONTROL, Keys.SUBTRACT);
    
        2
  •  0
  •   David    6 年前

    一般来说,您可以使用:

    Actions act = new Actions(driver);
    act.sendKeys(Keys.chord(Keys.CONTROL, "t"));
    

    除非你正在使用 Chrome驱动程序 臭虫 不允许发送某些命令:

    这些不行

    act.sendKeys(Keys.chord(Keys.CONTROL, "t"));
    act.sendKeys(Keys.chord(Keys.CONTROL, "n"));
    

    这项工作:

    // open in a new tab
    driver.findElement(By.id("linkID")).sendKeys(Keys.chord(Keys.CONTROL, Keys.ENTER));
    

    在某个时刻,他们可以解决这个错误,它将再次工作。 错误跟踪: https://bugs.chromium.org/p/chromedriver/issues/detail?id=581