硒(ime)在硒中究竟是什么?

时间:2014-10-27 13:17:35

标签: selenium ime

driverInstanceName.manage().ime().getActiveEngine()
driverInstanceName.manage().ime().activateEngine(engine)

获得如下的例外,

org.openqa.selenium.WebDriverException: 
unimplemented command: session/3f83e50445b7c179249aada785c8e910/ime/activate
Command duration or timeout: 2 milliseconds

理解它与输入数据有关但不确定它在硒中的相关性,尝试在许多论坛中找到答案,但无济于事。

1 个答案:

答案 0 :(得分:1)

有兴趣在阅读此问题后了解有关ime()方法的更多信息,并围绕此搜索谷歌搜索:

IME - 代表输入法引擎。目前看来这只支持Linux平台和Firefox浏览器。

使用需要由Linux中的Selenium输入的中文/日文或多字节字符时,必须使用IBus之类的输入框架和IBus上实现的引擎,如anthy(日文) ,pinyin(中文)。

以下代码示例来自Selenium的I18NTest.java,它查找anthy引擎以在linux机器上输入日文字符。

  @NeedsFreshDriver
  @Ignore(value = {IE, CHROME, FIREFOX},
          reason = "Not implemented on anything other than Firefox/Linux at the moment.")
  @NotYetImplemented(HTMLUNIT)
  @Test
  public void testShouldBeAbleToActivateIMEEngine() throws InterruptedException {
    assumeTrue("IME is supported on Linux only.",
               TestUtilities.getEffectivePlatform().is(Platform.LINUX));

    driver.get(pages.formPage);

    WebElement input = driver.findElement(By.id("working"));

    // Activate IME. By default, this keycode activates IBus input for Japanese.
    WebDriver.ImeHandler ime = driver.manage().ime();

    List<String> engines = ime.getAvailableEngines();
    String desiredEngine = "anthy";

    if (!engines.contains(desiredEngine)) {
      System.out.println("Desired engine " + desiredEngine + " not available, skipping test.");
      return;
    }

    ime.activateEngine(desiredEngine);

    int totalWaits = 0;
    while (!ime.isActivated() && (totalWaits < 10)) {
      Thread.sleep(500);
      totalWaits++;
    }
    assertTrue("IME Engine should be activated.", ime.isActivated());
    assertEquals(desiredEngine, ime.getActiveEngine());

    // Send the Romaji for "Tokyo". The space at the end instructs the IME to convert the word.
    input.sendKeys("toukyou ");
    input.sendKeys(Keys.ENTER);

    String elementValue = input.getAttribute("value");

    ime.deactivate();
    assertFalse("IME engine should be off.", ime.isActivated());

    // IME is not present. Don't fail because of that. But it should have the Romaji value
    // instead.
    assertTrue("The elemnt's value should either remain in Romaji or be converted properly."
        + " It was:" + elementValue, elementValue.equals(tokyo));
  }

警告:我的回答可能会对ime()提供一个公平的想法, selenium committers 可以提高更多的见解,因为我看到这个功能是没有广泛使用,也支持有限(仅限Linux)。