Java strings compare getText()
I have two strings, one is: String currentDoc= driver.findElement(By.cssSelector(".active .ng-scope:nth-child(2)")).getText();
and the outcome of it is:
First Name Last Name Remove Worker details Goran Dxxxxxc David Vxxxxć Matija Mxxxxc Andrej Txxxxk
second string is:
String docList = "First Name Last Name Remove Worker details\r\n" + "Goran Dxxxxxc\r\n" + "David Vxxxxć\r\n" + "Matija Mxxxxc\r\n" + "Andrej Txxxxk";
when I do: System.out.println(trenutniPopis.equals(currentDoc));
I always get false First I thought "ć" was the problem but replacing it with "c" in both cases made no difference. Any thoughts what could be the problem? thank you
New line can be represented by multiple characters:
\r\n
\n
\r
.
I would recommend to use regex.
String regex = "First Name Last Name Remove Worker details\\s+" + "Goran Dxxxxxc\\s+" + "David Vxxxxć\\s+" + "Matija Mxxxxc\\s+" + "Andrej Txxxxk"; System.out.println(currentDoc.matches(regex));
\s
– matches any whitespace character (equal to [\r\n\t\f\v ])
+
Quantifier — Matches between one and unlimited times