String source = "[[FirefoxDriver: firefox on WINDOWS (4520a9a1-c58b-4b34-ae3e-48613e6e7005)] -> xpath: //div[@class='page-title category-title']]"; //Split your Source from "->" String[] temp = source.split("-> "); //Split your Source from ": " String[] temp2 = temp[1].split(": "); //Access first index to get locator name String locator = temp2[0]; //Access Second index to get locator value String value = temp2[1].substring(0,temp2[1].length()-1);