Understanding the return value of getLocation () Selenium WebDriver API

There is a method in the Selenium WebDriver API getLocation()that returns a point containing the location of the upper left corner of an element. Let's say it returns (x, y).

Is the dot the (x, y)corresponding resolution of the desktop screen (browser when working in full screen mode) or a viewport (viewing area, visible area of ​​a web page in a browser window)?

EDIT

Based on my answer to this question, I can assume that it getLocation()returns a point with the corresponding resolution of the desktop screen or the entire browser (including the toolbar, search bar, etc.), and not viewport. I just want to make sure that if my thinking is correct and if so, why is the behavior getLocation()done in this way? Is there any Selenium WebDriver method that will return me an element element with an appropriate viewport?

Please correct if I am wrong.

+4
source share
3 answers

The "exact location" on the page, regardless of visibility.

, , , / .

, , , . element IWebElement, ICoordinates, IWebElement ICoordinates, .

    Point p = element.LocationOnScreenOnceScrolledIntoView;
    OpenQA.Selenium.Interactions.Internal.ICoordinates p2 = element.Coordinates;

. LocationOnScreenOnceScrolledIntoView , .

LocationInViewport, , , .

    p = p2.LocationInViewport;
    p = p2.LocationOnScreen;
    p = p2.LocationInDom;
    object obj = p2.AuxiliaryLocator;
+1

, ( , ..), .

. ( (x, y) ) . , , . , getLocation() . ,

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class DragAndDropUsingRobot {
    WebDriver driver = null;

    @BeforeClass
    public void setUp(){
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("http://www.w3schools.com/html/html5_draganddrop.asp");
    }

    @AfterClass
    public void tearDown(){
        driver.quit();
    }

    @Test
    public void testDragAndDrop() throws AWTException, InterruptedException{
        WebElement source = driver.findElement(By.id("div1")); 

        Robot robot = new Robot();
        Thread.sleep(2000);
        robot.mouseMove(source.getLocation().getX(), source.getLocation().getY());

        Thread.sleep(5000);
    }
}
0

( python) renderable canvas. , .

, - , Chrome, , :

'location': {'y': 6825, 'x': 519.5}, 'size': {'width': 476, 'height': 16}

, , . , location_once_scrolled_into_view, , , , :

, . .

, python , , AFAIK.

0

All Articles