String ActualValue = element.getAttribute("class");
String[] SplittedValue =ActualValue.split("");
輸出: object_selected object_notselected
如何將值列印object_selection在System.out.println(" ");
uj5u.com熱心網友回復:
看,這
SplittedValue
是string array,您可以通過多種方式列印陣列:
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");
}
不知道你為什么要這樣使用 split split(""),可能你正在尋找這個split(" ")
此外,如果您確定字串元素,那么您可以像這樣直接列印它們(不推薦):
String actualValue = driver.findElement(By.xpath("//")).getAttribute("class");
String[] splittedValue = actualValue.split(" ");
System.out.println(splittedValue[0]);
System.out.println(splittedValue[1]);
uj5u.com熱心網友回復:
你離得夠近了。一旦您檢索到classname的值,即object_selected object_notselected您可以呼叫split()以空格字符作為分隔符,如下所示:
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]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/409725.html
標籤:
上一篇:使用面向物件編程撰寫基類
