问题
I'm using Selenium WebDriver with Java. I'm trying to enter the text 'test' followed by 2 backslashes into a text field.
When I tried the following code -
driver.findElement(By.id("txtEditExcludeRegPath")).sendKeys("test\");
Only test\ is entered into the textbox. The remaining backslash is left out.
Can someone help me solve this problem.
Please note - Even in this post, I'm unable to view 2 consecutive slashes after 'test'. Only 1 \ gets posted.
回答1:
Try the code like this (Assuming you want the output as 'test\\'):
driver.findElement(By.id("txtEditExcludeRegPath")).sendKeys("test\\\\");
NOTE: Normally backslashes are used to escape the character after it, hence if you want to escape two backslashes you will have to add two backslashes to it.
来源:https://stackoverflow.com/questions/27294946/selenium-webdriver-using-java-sendkeys-with-double-slash