1

I'm trying to key a password containing a special character double quotes. I'm getting a compile time error in Java as expected for code mentioned below.

driver.findElement(By.id("cred_password_inputtext"))
  .sendKeys("ghsfdjfsg"ksdkhkh");
d.k
  • 4,234
  • 2
  • 26
  • 38
Dominic
  • 33
  • 1
  • 7
  • 1
    does the backslash escaping work in Java? I mean \" – d.k Jul 16 '16 at 09:48
  • you get the compile error, because to the compiler it looks like one string `"ghsfdjfsg"` followed by an unexpected tokens `ksdkhkh`. You need to try to escape the quotes with a backslash, i.e. sendKeys("ghsfdjfsg\"ksdkhkh"); – d.k Jul 16 '16 at 09:55
  • Thanks, it works. I was able execute the following code with backslash driver.findElement(By.id("cred_password_inputtext")) .sendKeys("ghsfdjfsg\"ksdkhkh"); – Dominic Jul 16 '16 at 10:39

1 Answers1

1

Use escape character '\' while sending the password. i.e;

    driver.findElement(By.id("cred_password_inputtext")).sendKeys("ghsfdjfsg\"ksdkhkh");
Harish
  • 306
  • 1
  • 4
  • 14