check target for three times

来源:互联网 发布:spss如何进行数据分组 编辑:程序博客网 时间:2024/06/07 05:57
package com.utility;import com.Bam.SeleniumSigleInstance;import com.myexception.MyException;import com.thoughtworks.selenium.Selenium;public class CheckXpath{private static Selenium selenium;static int count = 1;public static boolean checkXpathIsValid(String xpath) throws MyException,InterruptedException{selenium = SeleniumSigleInstance.getInstance();if (!selenium.isElementPresent(xpath)){Thread.sleep(3000);System.out.println("wait for " + count * 3000+ "s for the target...");//find the targets for three times if (count == 3){throw new MyException("can not find the xpath: " + xpath);}count++;//  recurrence the method checkXpathIsValid.checkXpathIsValid(xpath);}return true;}}