Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Jul 13, 2017 12:36

By Jeremy Payne

In the below article I will show the process of enabling the Eclipse feature which will automatically escape double quotes when pasting into a string literal.


When copying XPath from the Perfecto Object Spy you are copying XPath which surrounds string values with double quotes (").

Example: //*[@text="Login"]


And when pasting the XPath into Java code you must manually change the double quotes to either single quotes or escape the double quotes.

//*[@text='Login'] or //*[@text=\"Login\"]


Eclipse has a built in feature that will automatically escape double quote characters if it knows you are pasting the string inside of double quotes which are already present in the code editor.

For instance you can paste this: //*[@text="Login"]

Into this: driver.findElemementByXpath("");


And you will end up with this: driver.findElemementByXpath("//*[@text=\"Login\"]");

However if you paste into this: driver.findElementByXpath(); without the double quotes you simply end up with this: driver.findElemementByXpath(//*[@text="Login"]);. So make sure you are always pasting into "".

To enable this setting first go to Windows→Preferences

Next expand Java->Editor->Click on Typing

Check the box that says Escape text when pasting into a string literal