All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Holmos.webtest.element.tool.WebDriverElementExist Maven / Gradle / Ivy

There is a newer version: 1.0.2u10
Show newest version
package Holmos.webtest.element.tool;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import Holmos.webtest.Allocator;
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;
/**
 * 用来判断webdriver web元素是否存在的类,采用的是策略模式
 * @author 吴银龙(15857164387)
 * */
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;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy