0

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

0

2 Answers 2

3

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];
Sign up to request clarification or add additional context in comments.

Comments

0

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));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.