Selenium Webdriver using Java - sendkeys with double slash

烂漫一生 提交于 2020-08-11 04:04:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!