Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does ime() in selenium do?

Tags:

selenium

ime

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

getting exceptions like below,

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

Understood that it is related to inputting data but not sure how it is relevant in selenium, tried finding the answer in many forums but to no avail.

like image 644
Manoj Manjunath Avatar asked Oct 27 '14 13:10

Manoj Manjunath


People also ask

What is driver manage () timeouts () implicitlyWait?

1. implicitlyWait() This timeout is used to specify the amount of time the driver should wait while searching for an element if it is not immediately present.

What is manage () in Selenium?

Based on your question- driver is an instance of concrete class which implements WebDriver interface. manage() method returns an "Option interface" referred to as WebDriver.Options.

How do you wait for an element in Selenium?

Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, WebDriver will wait for the element before the exception occurs. Once the command is in place, Implicit Wait stays in place for the entire duration for which the browser is open.


1 Answers

Got interested to learn more about ime() method after reading this question and punched out google searches around this:

IME - stands for Input Method Engine. Currently seems like this is only supported in Linux platform and Firefox browser.

When working with Chinese/Japanese or multi-byte characters that needs to input by Selenium in linux, you have to use input framework like IBus and the engines implemented on IBus like anthy (Japanese), pinyin (Chinese).

The following code example is taken from Selenium's I18NTest.java, which looks for anthy engine to input Japanese characters on a linux machine.

  @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));
  }

Caution: My answer may give a fair idea about the ime(), still more insights can be improved by selenium committers, as I see this feature is not in widespread use and also has limited support (only in Linux).

like image 186
parishodak Avatar answered Sep 20 '22 04:09

parishodak