Created
June 19, 2014 08:50
-
-
Save nyilmaz/b5ce1ece6e284c5e4fe1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String escapeSeleniumXpathString(String toBeEscaped) { | |
Pattern pattern = Pattern.compile("[^'\"]+|['\"]"); | |
Matcher matcher = pattern.matcher(toBeEscaped); | |
final List<String> replaced = Lists.newArrayList(); | |
while(matcher.find()) { | |
replaced.add(matcher.group()); | |
} | |
return "concat(" + StringUtils.collectionToCommaDelimitedString(FluentIterable.from(replaced).transform(new Function<String, String>() { | |
@Override | |
public String apply(String input) { | |
if(input.equals("'")) { | |
return "\"'\""; | |
} | |
if(input.equals("\"")) { | |
return "'\"'"; | |
} | |
return "'" + input + "'"; | |
} | |
}).toList()) + ")"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment