java - 如何在java中循环解析已解析的字符串

标签 java selenium-webdriver

我有一个链接列表,它们正在增加 1,我想采用字符串类型的 xpath 并将其拆分到数字所在的位置,然后每次循环时将该数字更改为 1。

String vPath= "/html/body/section/section[2]/a[1]";
//so the number that's changing is in the last bracket 
String[] t = vPath.split("/a");

然后我想使用分割变量并循环。所以也许使用 for 循环。但是,我似乎有一个问题,我该如何做到这一点。我觉得应该是这样的

 For (int i=1; i < t(something here); i++{
 then the code of clicking should go here
 }   

请大家帮忙。

最佳答案

根据我对您问题的理解,解决方案如下:

         String vPath= "/html/body/section/section[2]/a[1]"; //sample url
         int size = 100; // no of links you want to generate as per your requirement
         String[] chunks = vPath.split("/a");
         String chunk = chunks[0];
         for(int index =1; index <= size;index++){
            System.out.println(chunk+"["+index+"]"); // printing generated urls
            //code of clicking...
        }

关于java - 如何在java中循环解析已解析的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19525609/

相关文章:

java - 类.forName ("com.mysql.jdbc.Driver").newInstance()

java - 如何使用java显示mongoDB数组

java - 如何模拟 @InjectMocks 类的方法?

java - 如何在 Java 中使用 Selenium 提交表单

python - 绕过 Microsoft Edge 上的 Selenium Webdriver 安全证书页面

java - Selenium Java - 错误 - org.openqa.selenium.support.ui.UnexpectedTagNameException : Element should have been "select" but was "input"

java - 如何防止购物车中出现重复商品?

java - EnterState() 转换如何工作? (光滑2D)

java - diver.findElements 在 Selenium 中被挂起

c# - OperaDriver 不工作