org.openqa.selenium.internal.Locatable Java Examples

The following examples show how to use org.openqa.selenium.internal.Locatable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BooleanFunctions.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 5 votes vote down vote up
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);
        }
    };
}
 
Example #2
Source File: MorelandWebElement.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Coordinates getCoordinates()
{
    if ( webElement instanceof Locatable )
    {
        if ( cachedCoordinates == null )
            cachedCoordinates = ( (Locatable) webElement ).getCoordinates();
    
        return cachedCoordinates;
    }
    else
        return null;
}
 
Example #3
Source File: LocatedElement.java    From jsflight with Apache License 2.0 5 votes vote down vote up
@Override
public Coordinates getCoordinates()
{
    try
    {
        return ((Locatable)delegate).getCoordinates();
    }
    catch (StaleElementReferenceException e)
    {
        reLocateElement();
        return getCoordinates();
    }
}
 
Example #4
Source File: HtmlElement.java    From seleniumtestsframework with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #5
Source File: Element.java    From JTAF-ExtWebDriver with Apache License 2.0 5 votes vote down vote up
/***
 * 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;
}
 
Example #6
Source File: Element.java    From JTAF-ExtWebDriver with Apache License 2.0 5 votes vote down vote up
/***
 * Scroll to this element
 */
@Override
public void scrollTo() throws WidgetException {
	WebElement we = findElement();	
	Locatable l = ((Locatable)we);
	l.getCoordinates().inViewPort();
}
 
Example #7
Source File: PlatformBasedActions.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Actions sendKeys(WebElement element, CharSequence... keysToSend) {
  action.addAction(
      new SendKeysAction(keyboard, mouse, (Locatable) element, modifyCharSequence(keysToSend)));
  return this;
}
 
Example #8
Source File: ScreenshotUtils.java    From JTAF-ExtWebDriver with Apache License 2.0 4 votes vote down vote up
/***
 * 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;
		}
	}
}