holmos.webtest.element.tool.WebDriverElementExist Maven / Gradle / Ivy
package holmos.webtest.element.tool;
import holmos.webtest.Allocator;
import holmos.webtest.constvalue.ConfigConstValue;
import holmos.webtest.constvalue.ConstValue;
import holmos.webtest.element.ListElement;
import holmos.webtest.element.locator.Locator;
import holmos.webtest.element.locator.LocatorFinder;
import holmos.webtest.element.locator.LocatorValue;
import holmos.webtest.struct.Collection;
import holmos.webtest.struct.Frame;
import holmos.webtest.struct.Page;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
/**
* 用来判断webdriver web元素是否存在的类,采用的是策略模式
*
* @author 吴银龙([email protected])
* */
public class WebDriverElementExist extends WebElementExist{
/**
* 元素的判断采用策略模式实现,此为WebDriver类型的数据判断
* @param webElement 待判断的元素
* */
public WebDriverElementExist(LocatorValue webElement){
super(webElement);
}
@Override
public boolean isElementExist(int waitCount){
initComment();
LocatorValue lastNode=infoChain.getInfoNodes().get(infoChain.getInfoNodes().size()-1);
if(lastNode instanceof Page || lastNode instanceof Frame){
return findOneLevelElement(waitCount);
}else{
return findMuiltiLevelElement(waitCount);
}
}
@Override
public boolean isElementExistForCheckOnce(){
LocatorValue lastNode=infoChain.getInfoNodes().get(infoChain.getInfoNodes().size()-1);
if(lastNode instanceof Page || lastNode instanceof Frame){
return findOneLevelElement(1);
}else{
return findMuiltiLevelElement(1);
}
}
private boolean findMuiltiLevelElement(int waitCount) {
int startLevel=infoChain.getInfoNodes().size()-1;
for(;startLevel>1;startLevel--){
if(infoChain.getInfoNodes().get(startLevel) instanceof Frame){
//找到Frame层级,跳到下一层
startLevel++;
break;
}
}
WebDriver driverTemp=(WebDriver) Allocator.getInstance().currentWindow.getDriver().getEngine();
WebElement elementTemp=null;
elementTemp=findElement(new LocatorFinder(driverTemp), infoChain.getInfoNodes().get(startLevel));
if(elementTemp==null)return false;
for(int i=startLevel+1;i1;startLevel--){
if(infoChain.getInfoNodes().get(startLevel) instanceof Frame){
//找到Frame层级,跳到下一层
startLevel++;
break;
}
}
WebDriver driverTemp=(WebDriver) Allocator.getInstance().currentWindow.getDriver().getEngine();
WebElement elementTemp=null;
elementTemp=findElement(new LocatorFinder(driverTemp), infoChain.getInfoNodes().get(startLevel));
if(elementTemp==null)return -1;
for(int i=startLevel+1;i