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");
Dmitry Koroliov
  • 3,979
  • 2
  • 24
  • 36
Dominic
  • 13
  • 4
  • 1
    does the backslash escaping work in Java? I mean \" – Dmitry Koroliov 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"); – Dmitry Koroliov 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
  • 225
  • 1
  • 4
  • 14