String ActualValue = element.getAttribute("class");
String[] SplittedValue =ActualValue.split("");
Output: object_selected object_notselected
How to print the value object_selection in System.out.println(" ");
CodePudding user response:
See, this
SplittedValue
is string array, and you can print array in multiple ways:
String actualValue = driver.findElement(By.xpath("//")).getAttribute("class");
String[] splittedValue = actualValue.split("");
System.out.println("Length of array:" splittedValue.length);
if (splittedValue.length > 0) {
for(String str: splittedValue) {
System.out.println(str);
}
}
else {
System.out.println("Since lenght is zero, split was not properly, you may wanna check what you are passing in split method");
}
Not sure why you are using split like this split(""), probably you are looking for this split(" ")
Also if you are sure about the string elements, then you can directly print them like this (Not recommended):
String actualValue = driver.findElement(By.xpath("//")).getAttribute("class");
String[] splittedValue = actualValue.split(" ");
System.out.println(splittedValue[0]);
System.out.println(splittedValue[1]);
CodePudding user response:
You were close enough. Once you retrieve the value of classname i.e. object_selected object_notselected you can invoke split() with respect to the space character as the delimiter as follows:
String ActualValue = element.getAttribute("class");
// ActualValue = "object_selected object_notselected"
String[] SplittedValue = ActualValue.split(" ");
//printing object_selected
System.out.println(SplittedValue[0]);
//printing object_notselected
System.out.println(SplittedValue[1]);
