gpt4 book ai didi

java - 如何打破java中的if循环

转载 作者:行者123 更新时间:2023-12-01 10:00:52 24 4
gpt4 key购买 nike

我尝试在单击一个元素后放置中断,但单击该元素后它会尝试再次迭代

for (int i = 1; i < tableSize; i++) {       
final List<WebElement> columnElements = tableRows.get(i).findElements(By.tagName("td"));
for(WebElement columnElement : columnElements) {
if(columnElement.getText().equalsIgnoreCase(alias)) {

findElement(By.xpath(button.replace("{rowValue}", String.valueOf(i)))).click();
findElement(By.xpath(("//tr[{rowValue}]" + text).replace("{rowValue}", String.valueOf(i)))).click();
break;
}
}
}

最佳答案

当您像这样编写 break 时,您只会破坏最本地的循环(在本例中为 for(WebElement columnElement : columnElements)):

如果您为外部循环设置循环名称,例如

 loopName:
for (int i = 1; i < tableSize; i++) {
....

然后你可以按照下面的代码所示来破解它:

loopName:
for (int i = 1; i < tableSize; i++) {
final List<WebElement> columnElements = tableRows.get(i).findElements(By.tagName("td"));
for(WebElement columnElement : columnElements) {
if(columnElement.getText().equalsIgnoreCase(alias)) {

findElement(By.xpath(button.replace("{rowValue}", String.valueOf(i)))).click();
findElement(By.xpath(("//tr[{rowValue}]" + text).replace("{rowValue}", String.valueOf(i)))).click();
break loopName;
}
}
}

这将使您脱离两个循环,这似乎正是您所要求的。

关于java - 如何打破java中的if循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36822177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com