类org.openqa.selenium.internal.Locatable源码实例Demo

下面列出了怎么用org.openqa.selenium.internal.Locatable的API类实例代码及写法,或者点击链接到github查看源代码。

public static Function<WebDriver, Boolean> elementHasStoppedMoving(final WebElement element) {
    return new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            Point initialLocation = ((Locatable) element).getCoordinates().inViewPort();
            try {
                Thread.sleep(50);
            } catch (InterruptedException ignored) {
                //ignored
            }
            Point finalLocation = ((Locatable) element).getCoordinates().inViewPort();
            return initialLocation.equals(finalLocation);
        }
    };
}
 
源代码2 项目: xframium-java   文件: MorelandWebElement.java
@Override
public Coordinates getCoordinates()
{
    if ( webElement instanceof Locatable )
    {
        if ( cachedCoordinates == null )
            cachedCoordinates = ( (Locatable) webElement ).getCoordinates();
    
        return cachedCoordinates;
    }
    else
        return null;
}
 
源代码3 项目: jsflight   文件: LocatedElement.java
@Override
public Coordinates getCoordinates()
{
    try
    {
        return ((Locatable)delegate).getCoordinates();
    }
    catch (StaleElementReferenceException e)
    {
        reLocateElement();
        return getCoordinates();
    }
}
 
源代码4 项目: seleniumtestsframework   文件: HtmlElement.java
/**
 * Forces a mouseOver event on the WebElement.
 */
public void mouseOver() {
    TestLogging.log("MouseOver " + this.toString());
    findElement();

    // build and perform the mouseOver with Advanced User Interactions API
    // Actions builder = new Actions(driver);
    // builder.moveToElement(element).build().perform();
    final Locatable hoverItem = (Locatable) element;
    final Mouse mouse = ((HasInputDevices) driver).getMouse();
    mouse.mouseMove(hoverItem.getCoordinates());
}
 
源代码5 项目: JTAF-ExtWebDriver   文件: Element.java
/***
 * Determine if the element is within the bounds of the window
 * 
 * @return true or false
 * @throws WidgetException
 */
public boolean isWithinBoundsOfWindow() throws WidgetException {
	
	JavascriptExecutor js = ((JavascriptExecutor) getGUIDriver().getWrappedDriver());
	
	// execute javascript to get scroll values
	Object top = js.executeScript("return document.body.scrollTop;");
	Object left = js.executeScript("return document.body.scrollLeft;");
	
	int scrollTop;
	int scrollLeft;
	try {
		scrollTop = Integer.parseInt(top+"");
		scrollLeft = Integer.parseInt(left+"");
	}
	catch(NumberFormatException e) {
		throw new WidgetException("There was an error parsing the scroll values from the page", getByLocator());
	}
	
	// calculate bounds
	Dimension dim = getGUIDriver().getWrappedDriver().manage().window().getSize();
	int windowWidth = dim.getWidth();
	int windowHeight = dim.getHeight();
	int x = ((Locatable)getWebElement()).getCoordinates().onPage().getX();
	int y = ((Locatable)getWebElement()).getCoordinates().onPage().getY();
	int relX = x - scrollLeft;
	int relY = y - scrollTop;
	return relX + findElement().getSize().getWidth() <= windowWidth && 
			relY + findElement().getSize().getHeight() <= windowHeight && 
				relX >= 0 && relY >= 0;
}
 
源代码6 项目: JTAF-ExtWebDriver   文件: Element.java
/***
 * Scroll to this element
 */
@Override
public void scrollTo() throws WidgetException {
	WebElement we = findElement();	
	Locatable l = ((Locatable)we);
	l.getCoordinates().inViewPort();
}
 
源代码7 项目: che   文件: PlatformBasedActions.java
@Override
public Actions sendKeys(WebElement element, CharSequence... keysToSend) {
  action.addAction(
      new SendKeysAction(keyboard, mouse, (Locatable) element, modifyCharSequence(keysToSend)));
  return this;
}
 
源代码8 项目: JTAF-ExtWebDriver   文件: ScreenshotUtils.java
/***
 * You can use this method to take your control pictures. Note that the file should be a png.
 * 
 * @param element
 * @param toSaveAs
 * @throws IOException 
 * @throws WidgetException 
 */
public static void takeScreenshotOfElement(IElement element, File toSaveAs) throws IOException, WidgetException {
	
	for(int i = 0; i < 10; i++) { //Loop up to 10x to ensure a clean screenshot was taken
		log.info("Taking screen shot of locator " + element.getByLocator() + " ... attempt #" + (i+1));
		
		//Scroll to element
		element.scrollTo();
		
		//Take picture of the page
		WebDriver wd = SessionManager.getInstance().getCurrentSession().getWrappedDriver();
		File screenshot;
		boolean isRemote = false;
		if(!(wd instanceof RemoteWebDriver)) {
			screenshot = ((TakesScreenshot) wd).getScreenshotAs(OutputType.FILE);		
		}
		else {
			Augmenter augmenter = new Augmenter();
			screenshot = ((TakesScreenshot) augmenter.augment(wd)).getScreenshotAs(OutputType.FILE);
			isRemote = true;
		}
		BufferedImage fullImage = ImageIO.read(screenshot);
		WebElement ele = element.getWebElement();
		
		//Parse out the picture of the element
		Point point = ele.getLocation();
		int eleWidth = ele.getSize().getWidth();
		int eleHeight = ele.getSize().getHeight();
		int x; 
		int y;
		if(isRemote) {
			x = ((Locatable)ele).getCoordinates().inViewPort().getX();
			y = ((Locatable)ele).getCoordinates().inViewPort().getY();
		}
		else {
			x = point.getX();
			y = point.getY();
		}
		log.debug("Screenshot coordinates x: "+x+", y: "+y);
		BufferedImage eleScreenshot = fullImage.getSubimage(x, y, eleWidth, eleHeight);	
		ImageIO.write(eleScreenshot, "png", screenshot);
		
		//Ensure clean snapshot (sometimes WebDriver takes bad pictures and they turn out all black)
		if(!isBlack(ImageIO.read(screenshot))) {
			FileUtils.copyFile(screenshot, toSaveAs);
			break;
		}
	}
}
 
 类所在包
 同包方法