0

I'm trying to test one specific Selenium's Actions class method, which is as below.

public Actions sendKeys(java.lang.CharSequence... keysToSend)

Sends keys to the active element. This differs from calling WebElement.sendKeys(CharSequence...) on the active element.

public class Demo_1 {
  private WebDriver driver;
  private Actions action;
  private String baseUrl;

  @Before
  public void setUp() throws Exception {
    File file = new File("C:\\Users\\ProgramFiles\\firefox.exe");
    FirefoxProfile profile = new FirefoxProfile();
    FirefoxBinary binary = new FirefoxBinary(file);
    driver = new FirefoxDriver(binary, profile);
    action = new Actions(driver);
    baseUrl = "http://www.mortgagecalculator.org";
  }

  @Test
  public void testUntitled() throws Exception { 
    driver.get(baseUrl + "/");
    driver.findElement(By.name("param[homevalue]")).click();
    driver.findElement(By.name("param[homevalue]")).clear();
    action.sendKeys("300000");
  }

  @After
  public void tearDown() throws Exception {
    //driver.quit();
  }
}

I can do this alternatively, but in some cases when there is no WebElement, action.sendKeys can help to send CharSequence without any WebElement as parameter.

Can some come up with similar kind of issue, as the above code is not working :(

1 Answer 1

4

Cause its Actions class object so you need to tell the driver the actions you are performing.

action.sendKeys("300000").perform();

Will do the needful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.