简体   繁体   English

Selenium Webdriver(Java)-数组中的裁剪字符串值

[英]Selenium Webdriver(Java) - crop string value from array

I have an array with values as: 我有一个数组的值为:

(C:), (D:), (E:) - I need to crop any of this value to get - C , D or E (C:),(D:),(E :) -我需要裁剪任何此值以获得-C,D或E

The array is : 数组是:

WebElement table =  new WebDriverWait(Login.driver, 30).until(ExpectedConditions.visibilityOfElementLocated
                (By.id("table1")));

List<WebElement> rows = table.findElements(By.id("td1"));
java.util.Iterator<WebElement> i = rows.iterator();

while(i.hasNext()) {
   WebElement row = i.next();
   cont = row.getText();
   System.out.println("Test1: "+cont);
}

I have tried to use 我尝试使用

    String[] v_split = cont.split(" ");
    String v_splCmpIc = v_split[0];

But this shown an array index. 但这显示了数组索引。

Is there any chance to crop an index as I showed above? 如上所示,是否有机会裁剪索引?

解决方案将是:

cont = row.getText().replace("(","").replace(")","").replace(":","");  // inside while

If value of string "count" is fixed length you. 如果字符串“ count”的值是固定长度的,那么您。 You can make use of substring() method. 您可以使用substring()方法。 You can see more details and samples here 您可以在此处查看更多详细信息和示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM