Reputation: 11
I have a simple text on a webpage like this :
TxtNum : 125483646348 Dt Sent : 042720130000
these 2 values will keep on changing on the webpage. This text is at the end of the page . I want to copy these 2 fields for every test case and paste them in an excel file. Please help.
Upvotes: 0
Views: 6825
Reputation: 985
Using Selenium you can get hold of the values. Something on following lines where someID is whatever ID your text come under on your webpage (there are other location methods like By.xpath or By.className etc which you can use):
WebDriver driver = new FirefoxDriver();
String text = driver.findElement(By.id("someID")).getText();
Pattern p = Pattern.compile("TxtNum : (\d+) Dt Sent : (\d+)");
Matcher m = p.matcher(text);
if (m.find()) {
System.out.println(m.group(1) + "," + m.group(2));
}
In the above code snippet I just printed out the matched values as csv data on stdout, but you can follow this post and put it in a csv file as well which can be later opened in xls.
Upvotes: 1