Reputation: 3728
Actual String before the Scrap
Bibliographic data: US6079404 (A) ― 2000-06-27
String h1 = driver.findElement(By.xpath("//*[@id='hedvalue']/h1"))
.getText().replace("Bibliographic data:", "").trim();
so in h1 got the result for "US6079404 (A) ― 2000-06-27"
my Expected Result:
1.need to store only the value (US6079404 (A) in that h1 String (Note: length Dynamic not a constant) 2.2000-06-27 - how to store this value in another string
Sample o/p
h1 - US6079404 (A1)
h2 - 2000-06-27
Upvotes: 0
Views: 52
Reputation: 15433
You can use Regular Expression to resolve it.
You also don't need to replace the Bibliographic data:
.
I suppose that the .getText()
gives you
Bibliographic data:US6079404 (A) ― 2000-06-27
RegEx for that string with groups would be like:
^Bibliographic data:(.*)\s―\s(.*)$
Java Code
String raw = driver.findElement(By.xpath("//*[@id='hedvalue']/h1")).getText();
Pattern pattern = Pattern.compile("^Bibliographic data:(.*)\\s―\\s(.*)$");
Matcher matcher = pattern.matcher(raw);
if(matcher.find()){
System.out.println(matcher.group(1));
System.out.println(matcher.group(2));
}
Upvotes: 0
Reputation: 234795
You can split the string:
String[] parts = driver.findElement(By.xpath("//*[@id='hedvalue']/h1"))
.getText().replace("Bibliographic data:", "").trim().split(" ― ");
String h1 = parts[0];
String h2 = parts[1];
Upvotes: 3