当系统调用下面给出waitforelement方法时,搜索元素花费了很多时间。有什么理由吗?或者我的代码中有什么问题,请在下面给出:
public void WaitForElement(int source, String elementName)
throws InterruptedException {
try {
for (int second = 0; second <= 60; second++) {
Thread.sleep(1000);
switch (source) {
case 1:
if (isElementPresent(By.id(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
} else {
}
case 2:
if (isElementPresent(By.xpath(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
}
case 3:
if (isElementPresent(By.name(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
}
case 4:
if (isElementPresent(By.className(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
}
case 5:
if (isElementPresent(By.cssSelector(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
}
case 6:
if (isElementPresent(By.linkText(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
}
case 7:
if (isElementPresent(By.partialLinkText(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
}
case 8:
if (isElementPresent(By.tagName(elementName))) {
System.out.println("Element Found :" + elementName);
second = 60;
break;
}
default:
System.out.println("Element not found: " + elementName);
}
}
} catch (Exception e) {
System.out.println(e);
}
Thread.sleep(1000);
}