How to use getX method of org.openqa.selenium.Point class

Best Selenium code snippet using org.openqa.selenium.Point.getX

Source:UICatalogTest.java Github

copy

Full Screen

...69 }70 private Point getCenter(WebElement element) {71 Point upperLeft = element.getLocation();72 Dimension dimensions = element.getSize();73 return new Point(upperLeft.getX() + dimensions.getWidth()/2, upperLeft.getY() + dimensions.getHeight()/2);74 }75 @Test76 public void testFindElement() throws Exception {77 //first view in UICatalog is a table78 MobileElement table = (MobileElement)driver.findElementByClassName("UIATableView");79 assertNotNull(table);80 //is number of cells/rows inside table correct81 List<WebElement> rows = table.findElementsByClassName("UIATableCell");82 assertEquals(12, rows.size());83 //is first one about buttons84 assertEquals("Buttons, Various uses of UIButton", rows.get(0).getAttribute("name"));85 //navigationBar is not inside table86 WebElement nav_bar = null;87 try {88 nav_bar = table.findElementByClassName("UIANavigationBar");89 } catch (NoSuchElementException e) {90 //expected91 }92 assertNull(nav_bar);93 //there is nav bar inside the app94 driver.getPageSource();95 nav_bar = driver.findElementByClassName("UIANavigationBar");96 assertNotNull(nav_bar);97 }98 @Test99 public void test_location() {100 //get third row location101 row = driver.findElementsByClassName("UIATableCell").get(2);102 assertEquals(0, row.getLocation().getX());103 assertEquals(152, row.getLocation().getY());104 }105 @Test106 public void testScreenshot() {107 //make screenshot and get is as base64108 WebDriver augmentedDriver = new Augmenter().augment(driver);109 String screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.BASE64);110 assertNotNull(screenshot);111 //make screenshot and save it to the local filesystem112 File file = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);113 assertNotNull(file);114 }115 @Test116 public void testTextFieldEdit() {117 //go to the text fields section118 openMenuPosition(2);119 WebElement text_field = driver.findElementsByClassName("UIATextField").get(0);120 //get default/empty text121 String default_val = text_field.getAttribute("value");122 //write some random text to element123 String rnd_string = RandomStringUtils.randomAlphanumeric(6);124 text_field.sendKeys(rnd_string);125 assertEquals(rnd_string, text_field.getAttribute("value"));126 //send some random keys127 String rnd_string2 = RandomStringUtils.randomAlphanumeric(6);128 Actions swipe = new Actions(driver).sendKeys(rnd_string2);129 swipe.perform();130 //check if text is there131 assertEquals(rnd_string + rnd_string2, text_field.getAttribute("value"));132 //clear133 text_field.clear();134 //check if is empty/has default text135 assertEquals(default_val, text_field.getAttribute("value"));136 }137 @Test138 public void testAlertInteraction() {139 //go to the alerts section140 openMenuPosition(10);141 //trigger modal alert with cancel & ok buttons142 List<WebElement> triggerOkCancel = driver.findElementsByAccessibilityId("Show OK-Cancel");143 triggerOkCancel.get(1).click();144 Alert alert = driver.switchTo().alert();145 //check if title of alert is correct146 assertEquals("UIAlertView <Alert message>", alert.getText());147 alert.accept();148 }149 @Test150 public void testScroll() {151 //scroll menu152 //get initial third row location153 row = driver.findElementsByClassName("UIATableCell").get(2);154 Point location1 = row.getLocation();155 Point center = getCenter(row);156 //perform swipe gesture157 driver.swipe(center.getX(), center.getY(), center.getX(), center.getY()-20, 1);158 //get new row coordinates159 Point location2 = row.getLocation();160 assertEquals(location1.getX(), location2.getX());161 assertNotSame(location1.getY(), location2.getY());162 }163 @Test164 public void testSlider() {165 //go to controls166 openMenuPosition(1);167 //get the slider168 WebElement slider = driver.findElementByClassName("UIASlider");169 assertEquals("50%", slider.getAttribute("value"));170 Point sliderLocation = getCenter(slider);171 driver.swipe(sliderLocation.getX(), sliderLocation.getY(), sliderLocation.getX()-100, sliderLocation.getY(), 1);172 assertEquals("0%", slider.getAttribute("value"));173 }174 @Test175 public void testSessions() throws Exception {176 HttpGet request = new HttpGet("http://localhost:4723/wd/hub/sessions");177 HttpClient httpClient = new DefaultHttpClient();178 HttpResponse response = httpClient.execute(request);179 HttpEntity entity = response.getEntity();180 JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity));181 String sessionId = driver.getSessionId().toString();182 assertEquals(jsonObject.get("sessionId"), sessionId);183 }184 @Test185 public void testSize() {...

Full Screen

Full Screen

Source:ClickonCmpnyndScroll.java Github

copy

Full Screen

...59 }60/*TouchAction action = new TouchAction(appiumDriver); 61Point upperleft = element.getLocation(); 62Dimension dimensions = element.getSize(); 63Point sliderLocation = new Point(upperleft.getX() + dimensions.getWidth()/2, upperleft.getY() + dimensions.getHeight()/2); 64action.press(sliderLocation.getX(), sliderLocation.getY()).waitAction(200).moveTo(sliderLocation.getX()+(sliderLocation.getX()-1), sliderLocation.getY()).release().perform();65*/66/*for down67 * int offset=1;68Point p = element.getCenter();69Point location = element.getLocation();70Dimension size = element.getSize();71appiumDriver.swipe(p.getX(), location.getY()+ size.getHeight() + offset, p.getX() , location.getY(), 5);*/72/**org.openqa.selenium.WebDriverException*//*73MobileElement element = (MobileElement) appiumDriver.findElement(By.className("android.widget.RelativeLayout"));74int offset=1;75Point p = element.getCenter();76Point location = element.getLocation();77Dimension size = element.getSize();78appiumDriver.swipe(p.getX(), location.getY(), p.getX() - offset, location.getY()+size.getHeight(), 0);*/79/*int time;80void swipeUpElement( appiumDriver, element , time)81{82 int topY = element.getLocation().getY();83 int bottomY = topY + element.getSize().getHeight();84 int centerX = element.getLocation().getX() + (element.getSize().getWidth()/2)85 appiumDriver.86 //swipe(centerX, bottomY, centerX, topY, time);87}*/88//DOWN {89// void swipe(AppiumDriver driver, MobileElement element, int duration) {90// int offset = 1;91// Point p = element.getCenter();92// Point location = element.getLocation();93// Dimension size = element.getSize();94// driver.swipe(p.getX(), location.getY(), p.getX() - offset, location.getY() + size.getHeight(), duration);95// }96//},97 System.out.println(1);98 /**not working*/99// Thread.sleep(7000);100// MobileElement element = (MobileElement) appiumDriver.findElement(By.className("android.widget.TextView"));101// 102// for (int i = 0; i < 3; i++) {103// element.swipe(SwipeElementDirection.UP, 88,697, 0);context("NATIVE_APP");104// }105 /**swipe left to right106 * http://stackoverflow.com/questions/28234045/appium-swipe-not-working-on-the-android-device-through-java-code*/ 107// appiumDriver.context("NATIVE_APP");108// Dimension size = appiumDriver.manage().window().getSize();...

Full Screen

Full Screen

Source:slideToUnlock.java Github

copy

Full Screen

...52 System.out.println(pic.size());53 pic.get(i).click();54 }55 final AndroidTouchAction touchAction = new AndroidTouchAction(driver);56 touchAction.press(PointOption.point(pic.get(0).getLocation().getX(), pic.get(0).getLocation().getY()))57 .waitAction()58 .moveTo(PointOption.point(pic.get(1).getLocation().getX() - pic.get(0).getLocation().getX(),59 pic.get(1).getLocation().getY() - pic.get(0).getLocation().getY()))60 .moveTo(PointOption.point(pic.get(2).getLocation().getX() - pic.get(1).getLocation().getX(),61 pic.get(2).getLocation().getY() - pic.get(1).getLocation().getY()))62 .moveTo(PointOption.point(pic.get(4).getLocation().getX() - pic.get(2).getLocation().getX(),63 pic.get(4).getLocation().getY() - pic.get(2).getLocation().getY()))64 .moveTo(PointOption.point(pic.get(6).getLocation().getX() - pic.get(4).getLocation().getX(),65 pic.get(6).getLocation().getY() - pic.get(4).getLocation().getY()))66 .moveTo(PointOption.point(pic.get(7).getLocation().getX() - pic.get(6).getLocation().getX(),67 pic.get(7).getLocation().getY() - pic.get(6).getLocation().getY()))68 .moveTo(PointOption.point(pic.get(8).getLocation().getX() - pic.get(7).getLocation().getX(),69 pic.get(8).getLocation().getY() - pic.get(7).getLocation().getY()))70 .release();71 touchAction.perform();72 /*73 * final TouchAction touchAction = new TouchAction(driver);74 * touchAction.press(pic.get(0)).waitAction(1500).moveTo(pic.get(1))75 * .moveTo(pic.get(2)).moveTo(pic.get(4)).moveTo(pic.get(6))76 * .moveTo(pic.get(7)).moveTo(pic.get(8)).release(); touchAction.perform();77 */78 String username = driver.findElement(By.id("cmb.pb:id/gTvMenuTitle")).getText();79 System.out.println(username);80 }81 @AfterClass(alwaysRun = true)82 public void tearDown() throws Exception {...

Full Screen

Full Screen

Source:WidgetImpl.java Github

copy

Full Screen

...63 public static void longtap(WebDriver driver, WebElement element) {64 if (driver instanceof HasTouchScreen) {65 TouchActions longtap = new TouchActions(driver);66 Point center = getCenter(element);67 longtap.down(center.getX(), center.getY());68 longtap.perform();69 try {70 Thread.sleep(750);71 } catch (InterruptedException e) {}72 longtap.up(center.getX(), center.getY());73 longtap.perform();74 } else {75 Locatable locatable = (Locatable) element;76 Coordinates coords = locatable.getCoordinates();77 Mouse mouse = ((HasInputDevices) driver).getMouse();78 mouse.mouseDown(coords);79 try {80 Thread.sleep(750);81 } catch (InterruptedException e) {}82 mouse.mouseUp(coords);83 }84 }85 86 protected static Point getCenter(WebElement element) {87 Dimension size = element.getSize();88 int halfWidth = size.getWidth() / 2;89 int halfHeight = size.getHeight() / 2;90 Point loc = element.getLocation();91 int posX = loc.getX() + halfWidth;92 int posY = loc.getY() + halfHeight;93 94 Point point = new Point(posX, posY);95 return point;96 }97 98 public void track(int x, int y, int step) {99 track(driver.getWebDriver(), contentElement, x, y, step);100 }101 102 public static void track(WebDriver driver, WebElement element, int x, int y, int step) {103 if (driver instanceof HasTouchScreen) {104 if (step == 0) {105 step = 1;106 // TODO: no move if step == 0107 }108 109 Point center = getCenter(element);110 111 int posX = center.getX();112 int posY = center.getY();113 114 int endX = posX + x;115 int endY = posY + y;116 TouchActions touchAction = new TouchActions(driver);117 touchAction.down(posX, posY);118 119 while ((x < 0 && posX > endX || x > 0 && posX < endX) || (y < 0 && posY> endY || y > 0 && posY < endY)) {120 if (x > 0 && posX < endX) {121 if (posX + step > endX) {122 posX += endX - (posX + step);123 } else {124 posX += step;125 }...

Full Screen

Full Screen

Source:SliderImagePractice.java Github

copy

Full Screen

...38 WebElement ten=driver.findElement(By.xpath(" //div[contains(@class,'horizontal')]//li[@title='10']"));39 WebElement zero=driver.findElement(By.xpath(" //div[contains(@class,'horizontal')]//li[@title='0']"));40 Point tenPoint=ten.getLocation();41 Point zeroPoint=zero.getLocation();42 System.out.println(tenPoint.getX());43 System.out.println(zeroPoint.getX());44 System.out.println(tenPoint.getX()-zeroPoint.getX());45 int difference= tenPoint.getX()-zeroPoint.getX();46 Actions actions=new Actions(driver);47 actions.clickAndHold(redCircle)48 .moveByOffset(difference+5,0)49 .release()50 .perform();51 }52}...

Full Screen

Full Screen

Source:Dimension.java Github

copy

Full Screen

...15 d.manage().window().maximize();16 17 // 1-way to get location and x-y axis18 Point loc5 = d.findElement(By.name("username")).getLocation();19 int z = d.findElement(By.name("username")).getLocation().getX();20 int w = d.findElement(By.name("username")).getLocation().getY();21 System.out.println("Username location"+loc5);22 System.out.println(z);23 System.out.println(w);24 25 Point loc2 = d.findElement(By.name("pwd")).getLocation();26 // (also can use) int loca = d.findElement(By.name("pwd")).getLocation().getX();27 int loca = loc2.getX();28 int locb = loc2.getY();29 System.out.println("Password :"+loc2);30 System.out.println("x :"+loca);31 System.out.println("y :"+locb);32 33 Point loc3 = d.findElement(By.id("loginButton")).getLocation();34 int locc = loc3.getX();35 int locd = loc3.getY();36 System.out.println("Login Button :"+loc3);37 System.out.println("x :"+locc);38 System.out.println("y :"+locd);39 40 // 1-way to get the height and width of the element41 42 int u = d.findElement(By.name("username")).getSize().getHeight();43 int u1 = d.findElement(By.name("username")).getSize().getWidth();44 int g = d.findElement(By.name("pwd")).getSize().getHeight();45 int g1 = d.findElement(By.name("pwd")).getSize().getWidth();46 int l = d.findElement(By.id("loginButton")).getSize().getHeight();47 int l1 = d.findElement(By.id("loginButton")).getSize().getWidth();48 49 System.out.println("\nUname \nheight :"+u +"\nwidth :"+u1);50 System.out.println("\nPwd \nheight :"+g +"\nwidth :"+g1);51 System.out.println("\nLogin \nheight :"+l +"\nwidth :"+l1);52 53 // 2nd way to get the location x-y axis54 55 WebElement ac = d.findElement(By.name("username"));56 Point loc1 = ac.getLocation();57 int locx = loc1.getX();58 int locy = loc1.getY();59 System.out.println("2nd way to get the coordinate: :"+loc1);60 System.out.println("x :"+locx);61 System.out.println("y :"+locy);62 6364 Thread.sleep(1000);65 6667 }6869} ...

Full Screen

Full Screen

Source:GetRectMethodConcept.java Github

copy

Full Screen

...24// System.out.println(loginButtonDim.getHeight());25// System.out.println(loginButtonDim.getWidth());26// 27// Point p = loginButton.getLocation();28// System.out.println(p.getX());29// System.out.println(p.getY());30// 31// //selenium 4:32// Rectangle loginButtonRect = loginButton.getRect();33// 34// System.out.println(loginButtonRect.getHeight());35// System.out.println(loginButtonRect.getWidth());36//37// System.out.println(loginButtonRect.getX());38// System.out.println(loginButtonRect.getY());39 40 driver.switchTo().newWindow(WindowType.WINDOW);41 driver.get("http://www.google.com");42 43 }44}...

Full Screen

Full Screen

Source:Get_Location.java Github

copy

Full Screen

...21 WebElement login=d.findElement(By.xpath("//a[@id='Login']"));22 23 Point loc =loginbutton.getLocation();24 25 int xcord=loc.getX();26 int ycord=loc.getY();27 28 System.out.println(xcord+"\t"+ycord);29 30 int a=loginbutton.getLocation().getX();31 int b=loginbutton.getLocation().getY();32 System.out.println(a+"\t"+b);33 34 int h=login.getSize().getHeight();35 int w=login.getSize().getWidth();36 System.out.println("height and width is"+"\t"+h+"\t"+w);37 38 Dimension D=login.getSize();39 int h1=D.height;40 int w2=D.width;41 42 System.out.println("height and width is "+"\t"+h1+"\t"+w2);43 44 int h3=login.getRect().getHeight();45 int w3=login.getRect().getWidth();46 47 int x1=login.getRect().getX();48 int y2=login.getRect().getY();49 System.out.println(h3+" "+w3+" "+x1+" "+y2);50 51 52 53 5455 }5657} ...

Full Screen

Full Screen

getX

Using AI Code Generation

copy

Full Screen

1Point point = driver.manage().window().getPosition();2int x = point.getX();3int y = point.getY();4Point point = driver.manage().window().getPosition();5System.out.println("X coordinate of browser is: "+point.getX());6System.out.println("Y coordinate of browser is: "+point.getY());

Full Screen

Full Screen

getX

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5public class GetXCoordinateOfElement {6public static void main(String[] args) {7 System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");8 WebDriver driver = new ChromeDriver();9 driver.manage().window().maximize();10 int x = element.getLocation().getX();11 System.out.println("X coordinate of the element is "+x);12 driver.close();13}14}

Full Screen

Full Screen

getX

Using AI Code Generation

copy

Full Screen

1Point location = driver.findElement(By.id("element_id")).getLocation();2int x = location.getX();3System.out.println("x coordinate of the element is: " + x);4Point location = driver.findElement(By.id("element_id")).getLocation();5int y = location.getY();6System.out.println("y coordinate of the element is: " + y);7Point location = driver.findElement(By.id("element_id")).getLocation();8int x = location.getX();9System.out.println("x coordinate of the element is: " + x);10Point location = driver.findElement(By.id("element_id")).getLocation();11int y = location.getY();12System.out.println("y coordinate of the element is: " + y);13Dimension size = driver.findElement(By.id("element_id")).getSize();14int height = size.getHeight();15System.out.println("height of the element is: " + height);16int width = size.getWidth();17System.out.println("width of the element is: " + width);18Dimension size = driver.findElement(By.id("element_id")).getSize();19int height = size.getHeight();20System.out.println("height of the element is: " + height);21Dimension size = driver.findElement(By.id("element_id")).getSize();22int width = size.getWidth();

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Point

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful