如何等待一个字符串元素获取其值,然后在java中写入它

时间:2017-07-06 11:11:08

标签: java multithreading selenium for-loop

我想在selenium java中编写一个脚本,我有for循环,其中我正在打印 count 的值,我的问题是它打印了值第二个语句中的第一个计数,第二个计数到第三个&等...... 只是它将第一个sysout语句留空并且首先将计数值打印到第二个sysout语句,依此类推。当我在打印前放置Thread.sleep()块时,它会起作用它,但我需要一个解决方案,检查计数有一些有效的计数&然后只打印语句,因为有些'count'需要2 +分钟来检索值,Thread只等待10秒而且也不是一个可行的解决方案来应用Thread.sleep() 这是我的代码块

for (int i = 0; i < numberOfElements; i++) {
        MS_items.get(i).click();
        String MS_Elem = MS_items.get(i).getAttribute("value");
        WebElement getCount = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@class='btn btn-info form-control margin-bottom'][.='Get Count']")));
        getCount.click();
        String count = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='alert alert-count']/p/b"))).getText();
        //Thread.sleep(10000);
        System.out.println("MS Name: " + MS_Elem + " count : "+ count);
        if(count!= "0"){
            MS_items.get(i).click();
        }

        if (count == "0") {
            Assert.assertEquals(false, false);
        }
    }
}

0 个答案:

没有答案
相关问题