Ticket Type Priority
Assigned Incident 3 - Medium
Acknowledgement Service Request 3 - Medium
Assigned Problem 2 - High
Assigned Incident 3 - Medium
Assigned Service Request 3 - Medium
Closed Incident 3 - Medium
Assigned Service Request 3 - Medium
Assigned Incident 2 - High
Closed Incident 3 - Medium
Assigned Service Request 3 - Medium
Assigned Service Request 3 - Medium
Acknowledgement Service Request 3 - Medium
Assigned Service Request 3 - Medium
Assigned Service Request 3 - Medium
Acknowledgement Service Request 3 - Mediumc
I am able to get above table data from webpage using java selenium.
I want to calculate
And store that value into csv file specific cell..
I have stored above table date in a variable.
public static void get_data() {
String txt = driver.findElement(By.xpath("//*[@class='jtrac jtrac- list']")).getText();
System.out.println(txt);
}
I have done earlier above things using powershell like this
$B = $A | Select-String "Incident","Problem" | measure-object; $C = $B.Count;
$obj[0].Measure = $C
$A contains above table data. Select-String select pattern string and measure. $obj handles Target csv file store data one by one $obj[*]
But i am not sure in Java.
Here is below Code. The Matcher object has extra methods for you to get more. Change the Pattern mentioned in method to suit your need.
String myTotalString= "Ticket Type Priority\n" +
" Assigned Incident 3 - Medium\n" +
" Acknowledgement Service Request 3 - Medium\n" +
" Assigned Problem 2 - High\n" +
" Assigned Incident 3 - Medium\n" +
" Assigned Service Request 3 - Medium\n" +
" Closed Incident 3 - Medium\n" +
" Assigned Service Request 3 - Medium\n" +
" Assigned Incident 2 - High\n" +
" Closed Incident 3 - Medium\n" +
" Assigned Service Request 3 - Medium\n" +
" Assigned Service Request 3 - Medium\n" +
" Acknowledgement Service Request 3 - Medium\n" +
" Assigned Service Request 3 - Medium\n" +
" Assigned Service Request 3 - Medium\n" +
" Acknowledgement Service Request 3 - Medium";
private int getIncidentOrProblems()
{
int i = 0;
Pattern p = Pattern.compile("Incident|Problem");
Matcher m = p.matcher( myTotalString );
while (m.find()) {
i++;
}
return i;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.