How to use Point class of org.openqa.selenium package

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

Source:DefaultAspect.java Github

copy

Full Screen

...15 */16package com.mengge.events;17import com.google.common.collect.ImmutableList;18import com.mengge.events.api.Listener;19import org.aspectj.lang.JoinPoint;20import org.aspectj.lang.ProceedingJoinPoint;21import org.aspectj.lang.annotation.After;22import org.aspectj.lang.annotation.Around;23import org.aspectj.lang.annotation.Aspect;24import org.aspectj.lang.annotation.Before;25import org.openqa.selenium.Alert;26import org.openqa.selenium.By;27import org.openqa.selenium.ContextAware;28import org.openqa.selenium.Dimension;29import org.openqa.selenium.Point;30import org.openqa.selenium.ScreenOrientation;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.WebElement;33import org.openqa.selenium.security.Credentials;34import org.springframework.context.support.AbstractApplicationContext;35import java.lang.reflect.InvocationTargetException;36import java.util.ArrayList;37import java.util.Collection;38import java.util.List;39@Aspect40class DefaultAspect {41 private static final List<Class<?>> listenable = ImmutableList.of(WebDriver.class,42 WebElement.class, WebDriver.Navigation.class, WebDriver.TargetLocator.class,43 ContextAware.class, Alert.class, WebDriver.Options.class, WebDriver.Window.class);44 private static final String EXECUTION_NAVIGATION_TO = "execution(* org.openqa.selenium.WebDriver."45 + "Navigation.get(..)) || "46 + "execution(* org.openqa.selenium.WebDriver.Navigation.to(..)) || "47 + "execution(* org.openqa.selenium.WebDriver.get(..))";48 private static final String EXECUTION_NAVIGATION_BACK = "execution(* org.openqa.selenium.WebDriver."49 + "Navigation.back(..))";50 private static final String EXECUTION_NAVIGATION_FORWARD = "execution(* org.openqa.selenium.WebDriver."51 + "Navigation.forward(..))";52 private static final String EXECUTION_NAVIGATION_REFRESH = "execution(* org.openqa.selenium.WebDriver."53 + "Navigation.refresh(..))";54 private static final String EXECUTION_SEARCH = "execution(* org.openqa.selenium.SearchContext."55 + "findElement(..)) || "56 + "execution(* org.openqa.selenium.SearchContext.findElements(..))";57 private static final String EXECUTION_CLICK = "execution(* org.openqa.selenium.WebElement.click(..))";58 private static final String EXECUTION_CHANGE_VALUE = "execution(* org.openqa.selenium.WebElement."59 + "sendKeys(..)) || "60 + "execution(* org.openqa.selenium.WebElement.clear(..)) || "61 + "execution(* AndroidElement.replaceValue(..)) || "62 + "execution(* MobileElement.setValue(..))";63 private static final String EXECUTION_SCRIPT = "execution(* org.openqa.selenium.JavascriptExecutor."64 + "executeScript(..)) || "65 + "execution(* org.openqa.selenium.JavascriptExecutor.executeAsyncScript(..))";66 private static final String EXECUTION_ALERT_ACCEPT = "execution(* org.openqa.selenium.Alert."67 + "accept(..))";68 private static final String EXECUTION_ALERT_DISMISS = "execution(* org.openqa.selenium.Alert."69 + "dismiss(..))";70 private static final String EXECUTION_ALERT_SEND_KEYS = "execution(* org.openqa.selenium.Alert."71 + "sendKeys(..))";72 private static final String EXECUTION_ALERT_AUTHENTICATION = "execution(* org.openqa.selenium."73 + "Alert.setCredentials(..)) || "74 + "execution(* org.openqa.selenium.Alert.authenticateUsing(..))";75 private static final String EXECUTION_WINDOW_SET_SIZE = "execution(* org.openqa.selenium."76 + "WebDriver.Window.setSize(..))";77 private static final String EXECUTION_WINDOW_SET_POSITION = "execution(* org.openqa.selenium.WebDriver."78 + "Window.setPosition(..))";79 private static final String EXECUTION_WINDOW_MAXIMIZE = "execution(* org.openqa.selenium.WebDriver."80 + "Window.maximize(..))";81 private static final String EXECUTION_ROTATE = "execution(* org.openqa.selenium.Rotatable"82 + ".rotate(..))";83 private static final String EXECUTION_CONTEXT = "execution(* org.openqa.selenium.ContextAware."84 + "context(..))";85 private static final String AROUND = "execution(* org.openqa.selenium.WebDriver.*(..)) || "86 + "execution(* org.openqa.selenium.WebElement.*(..)) || "87 + "execution(* org.openqa.selenium.WebDriver.Navigation.*(..)) || "88 + "execution(* org.openqa.selenium.WebDriver.Options.*(..)) || "89 + "execution(* org.openqa.selenium.WebDriver.TargetLocator.*(..)) || "90 + "execution(* org.openqa.selenium.WebDriver.TargetLocator.*(..)) || "91 + "execution(* org.openqa.selenium.JavascriptExecutor.*(..)) || "92 + "execution(* org.openqa.selenium.ContextAware.*(..)) || "93 + "execution(* FindsByAccessibilityId.*(..)) || "94 + "execution(* FindsByAndroidUIAutomator.*(..)) || "95 + "execution(* FindsByIosUIAutomation.*(..)) || "96 + "execution(* org.openqa.selenium.internal.FindsByClassName.*(..)) || "97 + "execution(* org.openqa.selenium.internal.FindsByCssSelector.*(..)) || "98 + "execution(* org.openqa.selenium.internal.FindsById.*(..)) || "99 + "execution(* org.openqa.selenium.internal.FindsByLinkText.*(..)) || "100 + "execution(* org.openqa.selenium.internal.FindsByName.*(..)) || "101 + "execution(* org.openqa.selenium.internal.FindsByTagName.*(..)) || "102 + "execution(* org.openqa.selenium.internal.FindsByXPath.*(..)) || "103 + "execution(* org.openqa.selenium.WebDriver.Window.*(..)) || "104 + "execution(* AndroidElement.*(..)) || "105 + "execution(* IOSElement.*(..)) || "106 + "execution(* AndroidDriver.*(..)) || "107 + "execution(* IOSDriver.*(..)) || "108 + "execution(* AppiumDriver.*(..)) || "109 + "execution(* MobileElement.*(..)) || "110 + "execution(* org.openqa.selenium.remote.RemoteWebDriver.*(..)) || "111 + "execution(* org.openqa.selenium.remote.RemoteWebElement.*(..)) || "112 + "execution(* org.openqa.selenium.Alert.*(..))";113 private final AbstractApplicationContext context;114 private final WebDriver driver;115 private final DefaultListener listener = new DefaultListener();116 private static Throwable getRootCause(Throwable thrown) {117 Class<? extends Throwable> throwableClass = thrown.getClass();118 if (!InvocationTargetException.class.equals(throwableClass) && !RuntimeException.class.equals(throwableClass)) {119 return thrown;120 }121 if (thrown.getCause() != null) {122 return getRootCause(thrown.getCause());123 }124 return thrown;125 }126 private static Class<?> getClassForProxy(Class<?> classOfObject) {127 Class<?> returnStatement = null;128 for (Class<?> c : listenable) {129 if (!c.isAssignableFrom(classOfObject)) {130 continue;131 }132 returnStatement = c;133 }134 return returnStatement;135 }136 DefaultAspect(AbstractApplicationContext context, WebDriver driver) {137 this.context = context;138 this.driver = driver;139 }140 private Object transformToListenable(Object toBeTransformed) {141 if (toBeTransformed == null) {142 return null;143 }144 Object result = null;145 if (getClassForProxy(toBeTransformed.getClass()) != null) {146 result = context.getBean(DefaultBeanConfiguration.COMPONENT_BEAN, toBeTransformed);147 }148 return result;149 }150 private List<Object> returnProxyList(List<Object> originalList) throws Exception {151 try {152 List<Object> proxyList = new ArrayList<>();153 for (Object o : originalList) {154 if (getClassForProxy(o.getClass()) == null) {155 proxyList.add(o);156 } else {157 proxyList.add(context.getBean(DefaultBeanConfiguration.COMPONENT_BEAN, o));158 }159 }160 return proxyList;161 } catch (Exception e) {162 throw e;163 }164 }165 public void add(Collection<Listener> listeners) {166 listener.add(listeners);167 }168 @Before(EXECUTION_NAVIGATION_TO)169 public void beforeNavigateTo(JoinPoint joinPoint) throws Throwable {170 try {171 listener.beforeNavigateTo(String.valueOf(joinPoint.getArgs()[0]), driver);172 } catch (Throwable t) {173 throw getRootCause(t);174 }175 }176 @After(EXECUTION_NAVIGATION_TO)177 public void afterNavigateTo(JoinPoint joinPoint) throws Throwable {178 try {179 listener.afterNavigateTo(String.valueOf(joinPoint.getArgs()[0]), driver);180 } catch (Throwable t) {181 throw getRootCause(t);182 }183 }184 @Before(EXECUTION_NAVIGATION_BACK)185 public void beforeNavigateBack(JoinPoint joinPoint) throws Throwable {186 try {187 listener.beforeNavigateBack(driver);188 } catch (Throwable t) {189 throw getRootCause(t);190 }191 }192 @After(EXECUTION_NAVIGATION_BACK)193 public void afterNavigateBack(JoinPoint joinPoint) throws Throwable {194 try {195 listener.afterNavigateBack(driver);196 } catch (Throwable t) {197 throw getRootCause(t);198 }199 }200 @Before(EXECUTION_NAVIGATION_FORWARD)201 public void beforeNavigateForward(JoinPoint joinPoint) throws Throwable {202 try {203 listener.beforeNavigateForward(driver);204 } catch (Throwable t) {205 throw getRootCause(t);206 }207 }208 @After(EXECUTION_NAVIGATION_FORWARD)209 public void afterNavigateForward(JoinPoint joinPoint) throws Throwable {210 try {211 listener.afterNavigateForward(driver);212 } catch (Throwable t) {213 throw getRootCause(t);214 }215 }216 @Before(EXECUTION_NAVIGATION_REFRESH)217 public void beforeNavigateRefresh(JoinPoint joinPoint) throws Throwable {218 try {219 listener.beforeNavigateRefresh(driver);220 } catch (Throwable t) {221 throw getRootCause(t);222 }223 }224 @After(EXECUTION_NAVIGATION_REFRESH)225 public void afterNavigateRefresh(JoinPoint joinPoint) throws Throwable {226 try {227 listener.afterNavigateRefresh(driver);228 } catch (Throwable t) {229 throw getRootCause(t);230 }231 }232 @SuppressWarnings("unchecked")233 private <T extends Object> T castArgument(JoinPoint joinPoint, int argIndex) {234 return (T) joinPoint.getArgs()[argIndex];235 }236 @SuppressWarnings("unchecked")237 private <T extends Object> T castTarget(JoinPoint joinPoint) {238 return (T) joinPoint.getTarget();239 }240 @Before(EXECUTION_SEARCH)241 public void beforeFindBy(JoinPoint joinPoint) throws Throwable {242 try {243 Object target = joinPoint.getTarget();244 if (!WebElement.class.isAssignableFrom(target.getClass())) {245 listener.beforeFindBy((By) castArgument(joinPoint, 0), null, driver);246 } else {247 listener.beforeFindBy((By) castArgument(joinPoint, 0),248 (WebElement) castTarget(joinPoint), driver);249 }250 } catch (Throwable t) {251 throw getRootCause(t);252 }253 }254 @After(EXECUTION_SEARCH)255 public void afterFindBy(JoinPoint joinPoint) throws Throwable {256 try {257 Object target = joinPoint.getTarget();258 if (!WebElement.class.isAssignableFrom(target.getClass())) {259 listener.afterFindBy((By) castArgument(joinPoint, 0), null, driver);260 } else {261 listener.afterFindBy((By) castArgument(joinPoint, 0),262 (WebElement) castTarget(joinPoint), driver);263 }264 } catch (Throwable t) {265 throw getRootCause(t);266 }267 }268 @Before(EXECUTION_CLICK)269 public void beforeClickOn(JoinPoint joinPoint) throws Throwable {270 try {271 listener.beforeClickOn((WebElement) castTarget(joinPoint), driver);272 } catch (Throwable t) {273 throw getRootCause(t);274 }275 }276 @After(EXECUTION_CLICK)277 public void afterClickOn(JoinPoint joinPoint) throws Throwable {278 try {279 listener.afterClickOn((WebElement) castTarget(joinPoint), driver);280 } catch (Throwable t) {281 throw getRootCause(t);282 }283 }284 @Before(EXECUTION_CHANGE_VALUE)285 public void beforeChangeValueOf(JoinPoint joinPoint) throws Throwable {286 try {287 listener.beforeChangeValueOf((WebElement) castTarget(joinPoint), driver);288 } catch (Throwable t) {289 throw getRootCause(t);290 }291 }292 @After(EXECUTION_CHANGE_VALUE)293 public void afterChangeValueOf(JoinPoint joinPoint) throws Throwable {294 try {295 listener.afterChangeValueOf((WebElement) castTarget(joinPoint), driver);296 } catch (Throwable t) {297 throw getRootCause(t);298 }299 }300 @Before(EXECUTION_SCRIPT)301 public void beforeScript(JoinPoint joinPoint) throws Throwable {302 try {303 listener.beforeScript(String.valueOf(joinPoint.getArgs()[0]), driver);304 } catch (Throwable t) {305 throw getRootCause(t);306 }307 }308 @After(EXECUTION_SCRIPT)309 public void afterScript(JoinPoint joinPoint) throws Throwable {310 try {311 listener.afterScript(String.valueOf(joinPoint.getArgs()[0]), driver);312 } catch (Throwable t) {313 throw getRootCause(t);314 }315 }316 @Before(EXECUTION_ALERT_ACCEPT)317 public void beforeAlertAccept(JoinPoint joinPoint) throws Throwable {318 try {319 listener.beforeAlertAccept(driver, (Alert) castTarget(joinPoint));320 } catch (Throwable t) {321 throw getRootCause(t);322 }323 }324 @After(EXECUTION_ALERT_ACCEPT)325 public void afterAlertAccept(JoinPoint joinPoint) throws Throwable {326 try {327 listener.afterAlertAccept(driver, (Alert) castTarget(joinPoint));328 } catch (Throwable t) {329 throw getRootCause(t);330 }331 }332 @Before(EXECUTION_ALERT_DISMISS)333 public void beforeAlertDismiss(JoinPoint joinPoint) throws Throwable {334 try {335 listener.beforeAlertDismiss(driver, (Alert) castTarget(joinPoint));336 } catch (Throwable t) {337 throw getRootCause(t);338 }339 }340 @After(EXECUTION_ALERT_DISMISS)341 public void afterAlertDismiss(JoinPoint joinPoint) throws Throwable {342 try {343 listener.afterAlertDismiss(driver, (Alert) castTarget(joinPoint));344 } catch (Throwable t) {345 throw getRootCause(t);346 }347 }348 @Before(EXECUTION_ALERT_SEND_KEYS)349 public void beforeAlertSendKeys(JoinPoint joinPoint) throws Throwable {350 try {351 listener.beforeAlertSendKeys(driver, (Alert) castTarget(joinPoint),352 String.valueOf(joinPoint.getArgs()[0]));353 } catch (Throwable t) {354 throw getRootCause(t);355 }356 }357 @After(EXECUTION_ALERT_SEND_KEYS)358 public void afterAlertSendKeys(JoinPoint joinPoint) throws Throwable {359 try {360 listener.afterAlertSendKeys(driver, (Alert) castTarget(joinPoint),361 String.valueOf(joinPoint.getArgs()[0]));362 } catch (Throwable t) {363 throw getRootCause(t);364 }365 }366 @Before(EXECUTION_ALERT_AUTHENTICATION)367 public void beforeAlertAuthentication(JoinPoint joinPoint) throws Throwable {368 try {369 listener.beforeAuthentication(driver,370 (Alert) castTarget(joinPoint), (Credentials) castArgument(joinPoint, 0));371 } catch (Throwable t) {372 throw getRootCause(t);373 }374 }375 @After(EXECUTION_ALERT_AUTHENTICATION)376 public void afterAlertAuthentication(JoinPoint joinPoint) throws Throwable {377 try {378 listener.afterAuthentication(driver, (Alert) castTarget(joinPoint),379 (Credentials) castArgument(joinPoint, 0));380 } catch (Throwable t) {381 throw getRootCause(t);382 }383 }384 @Before(EXECUTION_WINDOW_SET_SIZE)385 public void beforeWindowIsResized(JoinPoint joinPoint) throws Throwable {386 try {387 listener.beforeWindowChangeSize(driver,388 (WebDriver.Window) castTarget(joinPoint), (Dimension) castArgument(joinPoint, 0));389 } catch (Throwable t) {390 throw getRootCause(t);391 }392 }393 @After(EXECUTION_WINDOW_SET_SIZE)394 public void afterWindowIsResized(JoinPoint joinPoint) throws Throwable {395 try {396 listener.afterWindowChangeSize(driver, (WebDriver.Window) castTarget(joinPoint),397 (Dimension) castArgument(joinPoint, 0));398 } catch (Throwable t) {399 throw getRootCause(t);400 }401 }402 @Before(EXECUTION_WINDOW_SET_POSITION)403 public void beforeWindowIsMoved(JoinPoint joinPoint) throws Throwable {404 try {405 listener.beforeWindowIsMoved(driver, (WebDriver.Window) castTarget(joinPoint),406 (Point) castArgument(joinPoint, 0));407 } catch (Throwable t) {408 throw getRootCause(t);409 }410 }411 @After(EXECUTION_WINDOW_SET_POSITION)412 public void afterWindowIsMoved(JoinPoint joinPoint) throws Throwable {413 try {414 listener.afterWindowIsMoved(driver, (WebDriver.Window) castTarget(joinPoint),415 (Point) castArgument(joinPoint, 0));416 } catch (Throwable t) {417 throw getRootCause(t);418 }419 }420 @Before(EXECUTION_WINDOW_MAXIMIZE)421 public void beforeMaximization(JoinPoint joinPoint) throws Throwable {422 try {423 listener.beforeWindowIsMaximized(driver, (WebDriver.Window) castTarget(joinPoint));424 } catch (Throwable t) {425 throw getRootCause(t);426 }427 }428 @After(EXECUTION_WINDOW_MAXIMIZE)429 public void afterMaximization(JoinPoint joinPoint) throws Throwable {430 try {431 listener.afterWindowIsMaximized(driver, (WebDriver.Window) castTarget(joinPoint));432 } catch (Throwable t) {433 throw getRootCause(t);434 }435 }436 @Before(EXECUTION_ROTATE)437 public void beforeRotation(JoinPoint joinPoint) throws Throwable {438 try {439 listener.beforeRotation(driver, (ScreenOrientation) castArgument(joinPoint, 0));440 } catch (Throwable t) {441 throw getRootCause(t);442 }443 }444 @After(EXECUTION_ROTATE)445 public void afterRotation(JoinPoint joinPoint) throws Throwable {446 try {447 listener.afterRotation(driver, (ScreenOrientation) castArgument(joinPoint, 0));448 } catch (Throwable t) {449 throw getRootCause(t);450 }451 }452 @Before(EXECUTION_CONTEXT)453 public void beforeSwitchingToContext(JoinPoint joinPoint) throws Throwable {454 try {455 listener.beforeSwitchingToContext(driver, String.valueOf(joinPoint.getArgs()[0]));456 } catch (Throwable t) {457 throw getRootCause(t);458 }459 }460 @After(EXECUTION_CONTEXT)461 public void afterSwitchingToContextn(JoinPoint joinPoint) throws Throwable {462 try {463 listener.afterSwitchingToContext(driver, String.valueOf(joinPoint.getArgs()[0]));464 } catch (Throwable t) {465 throw getRootCause(t);466 }467 }468 @Around(AROUND)469 public Object doAround(ProceedingJoinPoint point) throws Throwable {470 Throwable t = null;471 Object result = null;472 try {473 result = point.proceed();474 } catch (Throwable e) {475 t = e;476 }477 if (t != null) {478 Throwable rootCause = getRootCause(t);479 listener.onException(rootCause, driver);480 throw rootCause;481 }482 if (result == null) { // maybe it was "void"483 return result;...

Full Screen

Full Screen

Source:CommonFunctions.java Github

copy

Full Screen

...9import io.appium.java_client.AppiumDriver;10import io.appium.java_client.MobileBy;11import io.appium.java_client.MobileElement;12import io.appium.java_client.TouchAction;13import io.appium.java_client.touch.offset.PointOption;1415public class CommonFunctions {16private static AppiumDriver<WebElement> driver;17public CommonFunctions()18{19 20}21public CommonFunctions(AppiumDriver<WebElement> driver)22{23 this.driver=driver;24}25public void swipe(WebElement startPoint,WebElement endPoint)26{27 TouchAction action = new TouchAction(driver);28 PointOption p1 = new PointOption();29 org.openqa.selenium.Point centerOfFirstElement = ((MobileElement) startPoint).getCenter();30 org.openqa.selenium.Point centerOfLastElement = ((MobileElement) endPoint).getCenter();31 //System.out.println("center of first element: "+centerOfFirstElement+ " center of last element: "+centerOfLastElement);32 new TouchAction(driver).longPress(p1.point(centerOfFirstElement.x, centerOfFirstElement.y+350))33 .moveTo(p1.point(centerOfLastElement.x, centerOfLastElement.y)).release().perform();34}3536 /*37 * public static void swipeInListTillExpectedTextAndTap1(List<WebElement> list,38 * String expectedText, int time) { int i = 1; while39 * (!driver.getPageSource().contains(expectedText)) { swipeList(list); i++; if40 * (i == time) break; } driver.findElement(MobileBy.41 * AndroidUIAutomator("new UiSelector().textContains(\"" +expectedText +42 * "\")")).click();; }43 */44public static void swipeList(List<WebElement> list) {45 int items = list.size();46 TouchAction action = new TouchAction(driver);47 PointOption p1 = new PointOption();48 org.openqa.selenium.Point centerOfFirstElement = ((MobileElement) list.get(0)).getCenter();49 org.openqa.selenium.Point centerOfLastElement = ((MobileElement) list.get(items - 1)).getCenter();50 //System.out.println("center of first element: "+centerOfFirstElement+ " center of last element: "+centerOfLastElement);51 new TouchAction(driver).longPress(p1.point(centerOfFirstElement.x, centerOfFirstElement.y+300))52 .moveTo(p1.point(centerOfLastElement.x, centerOfLastElement.y+80)).release().perform();53 54}55public void screenSwipe() {56 Dimension dimensions = driver.manage().window().getSize();57 System.out.println("Size of Window= " +dimensions);58 int scrollStart = (int) (dimensions.getHeight() * 0.5);59 System.out.println("Size of scrollStart= " +scrollStart);60 int scrollEnd = (int) (dimensions.getHeight() * 0.2);61 System.out.println("Size of cscrollEnd= " + scrollEnd); 62 // driver.swipe(0,scrollStart,0,scrollEnd,1000); 63 System.out.println("Screen Swiped " );64 //int items = list.size();65 TouchAction action = new TouchAction(driver);66 PointOption p1 = new PointOption();67 //org.openqa.selenium.Point centerOfFirstElement = ((MobileElement) list.get(0)).getCenter();68 //org.openqa.selenium.Point centerOfLastElement = ((MobileElement) list.get(items - 1)).getCenter();69 //System.out.println("center of first element: "+centerOfFirstElement+ " center of last element: "+centerOfLastElement);70 new TouchAction(driver).longPress(p1.point(scrollStart, scrollEnd))71 .moveTo(p1.point(scrollStart+100, scrollEnd+80)).release().perform();72 73 74}75public static void swipeUp(List<WebElement> list) {76 int items = list.size();77 //System.out.println("List Size is: "+ items);78 TouchAction action = new TouchAction(driver);79 PointOption p1 = new PointOption();80 org.openqa.selenium.Point centerOfFirstElement = ((MobileElement) list.get(0)).getCenter();81 org.openqa.selenium.Point centerOfLastElement = ((MobileElement) list.get(items - 1)).getCenter();82 //System.out.println("center of first element: "+centerOfFirstElement+ " center of last element: "+centerOfLastElement);83 new TouchAction(driver).longPress(p1.point(centerOfFirstElement.x, centerOfFirstElement.y+800))84 .moveTo(p1.point(centerOfLastElement.x, centerOfLastElement.y-1000)).release().perform();85 86}87public void swiptToBottom()88{89 PointOption p1 = new PointOption();90 Dimension dim = driver.manage().window().getSize();91 int height = dim.getHeight();92 int width = dim.getWidth();93 int x = width/2;94 int top_y = (int)(height*0.80);95 int bottom_y = (int)(height*0.05);96 System.out.println("coordinates :" + x + " "+ top_y + " "+ bottom_y);97 TouchAction ts = new TouchAction(driver);98 ts.longPress(p1.point(x, top_y)).moveTo(p1.point(x, bottom_y)).release().perform();99}100public void swiptToTop()101{102 PointOption p1 = new PointOption();103 Dimension dim = driver.manage().window().getSize();104 int height = dim.getHeight();105 int width = dim.getWidth();106 int x = width/2;107 int top_y = (int)(height*0.80);108 int bottom_y = (int)(height*0.25);109 System.out.println("coordinates :" + x + " "+ top_y + " "+ bottom_y);110 TouchAction ts = new TouchAction(driver);111 ts.longPress(p1.point(x, bottom_y)).moveTo(p1.point(x, top_y)).release().perform();112}113public static void swipeInListFromFirstToLast(List<WebElement> list) {114 int items = list.size();115 //System.out.println("List Size is: "+ items);116 TouchAction action = new TouchAction(driver);117 PointOption p1 = new PointOption();118 org.openqa.selenium.Point centerOfFirstElement = ((MobileElement) list.get(0)).getCenter();119 org.openqa.selenium.Point centerOfLastElement = ((MobileElement) list.get(items - 1)).getCenter();120 //System.out.println("center of first element: "+centerOfFirstElement+ " center of last element: "+centerOfLastElement);121 new TouchAction(driver).longPress(p1.point(centerOfLastElement.x, centerOfLastElement.y+100))122 .moveTo(p1.point(centerOfFirstElement.x, centerOfFirstElement.y+80)).release().perform();123 124}125public static void swipeInListTillExpectedTextAndTap1(List<WebElement> list, String expectedText, int time) {126 int i = 1;127 while (!driver.getPageSource().contains(expectedText)) {128 swipeInListFromFirstToLast(list);129 i++;130 if (i == time)131 break;132 }133 driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().textContains(\"" +expectedText + "\")")).click();; ...

Full Screen

Full Screen

Source:TestContext.java Github

copy

Full Screen

2package support;3import io.github.bonigarcia.wdm.WebDriverManager;4import org.openqa.selenium.Dimension;5import org.openqa.selenium.Platform;6import org.openqa.selenium.Point;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.chrome.ChromeDriver;9import org.openqa.selenium.chrome.ChromeOptions;10import org.openqa.selenium.edge.EdgeDriver;11import org.openqa.selenium.firefox.FirefoxBinary;12import org.openqa.selenium.firefox.FirefoxDriver;13import org.openqa.selenium.firefox.FirefoxOptions;14import org.openqa.selenium.ie.InternetExplorerDriver;15import org.openqa.selenium.remote.DesiredCapabilities;16import org.openqa.selenium.remote.RemoteWebDriver;17import org.openqa.selenium.safari.SafariDriver;18import java.net.MalformedURLException;19import java.net.URL;20import java.util.HashMap;21import java.util.Map;22public class TestContext {23 private static WebDriver driver;24 public static WebDriver getDriver() {25 return driver;26 }27 public static void initialize() {28 initialize("chrome", "local", false);29 }30 public static void teardown() {31 driver.quit();32 }33 public static void initialize(String browser, String testEnv, boolean isHeadless) {34 Dimension size = new Dimension(1920, 1080);35 Point position = new Point(0, 0);36 if (testEnv.equals("local")) {37 switch (browser) {38 case "chrome":39 WebDriverManager.chromedriver().setup();40 Map<String, Object> chromePreferences = new HashMap<>();41 chromePreferences.put("profile.default_content_settings.geolocation", 2);42 chromePreferences.put("download.prompt_for_download", false);43 chromePreferences.put("download.directory_upgrade", true);44 chromePreferences.put("credentials_enable_service", false);45 chromePreferences.put("password_manager_enabled", false);46 chromePreferences.put("safebrowsing.enabled", true);47 ChromeOptions chromeOptions = new ChromeOptions();48 chromeOptions.addArguments("--start-maximized");49 chromeOptions.setExperimentalOption("prefs", chromePreferences);...

Full Screen

Full Screen

Source:Home.java Github

copy

Full Screen

...5import java.io.File;6import javax.imageio.ImageIO;7import org.openqa.selenium.By;8import org.openqa.selenium.OutputType;9import org.openqa.selenium.Point;10import org.openqa.selenium.TakesScreenshot;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.support.FindBy;14import org.openqa.selenium.support.PageFactory;15import org.openqa.selenium.firefox.FirefoxDriver;16import org.openqa.selenium.internal.WrapsDriver;17import org.openqa.selenium.WebDriver;18import org.openqa.selenium.WebElement;19import org.openqa.selenium.By;20 21 22 23import net.sourceforge.tess4j.*;24import java.io.File;25public class Home {26 27 @FindBy(id="link_join") WebElement freeJoinLink;28 @FindBy(id="firstname") WebElement Firstname;29 @FindBy(id="email") WebElement Email;30 @FindBy(id="pwd-txt") WebElement pwdtxt;31 @FindBy(id="mobile_number") WebElement mobile_number;32 @FindBy(id="to_be_check") WebElement to_be_check;33 @FindBy(id="join_free_submit") WebElement join_free_submit;34 WebDriver driver;35 String firstname;36 String email;37 String phonNumber;38 String Password;39 int captchaCount;40 41 public Home(WebDriver driver)42 {43 this.driver=driver;44 PageFactory.initElements(driver, this);45 }46 47 public void clickJoinFreeButton () throws InterruptedException48 {49 freeJoinLink.click();50 Thread.sleep(3000);51 }52 53 public void enterSignUpDetails(String firstname,54 String email,55 String phonNumber,56 String Password57 ) throws Exception {58 59 this.firstname=firstname;60 this.email=email;61 this.Password=Password;62 this.phonNumber=phonNumber;63 this.clickJoinFreeButton();64 Firstname.sendKeys(firstname);65 Email.sendKeys(email);66 mobile_number.sendKeys(phonNumber);67 pwdtxt.sendKeys(Password);68 this.readCapcha();69 70 Thread.sleep(3000);71 72 73 74 75 }76 77 public static File captureElementPicture(WebElement element)78 throws Exception {79 80 // get the WrapsDriver of the WebElement81 WrapsDriver wrapsDriver = (WrapsDriver) element;82 83 // get the entire screenshot from the driver of passed WebElement84 File screen = ((TakesScreenshot) wrapsDriver.getWrappedDriver())85 .getScreenshotAs(OutputType.FILE);86 87 // create an instance of buffered image from captured screenshot88 BufferedImage img = ImageIO.read(screen);89 90 // get the width and height of the WebElement using getSize()91 int width = element.getSize().getWidth();92 int height = element.getSize().getHeight();93 94 // create a rectangle using width and height95 Rectangle rect = new Rectangle(width, height);96 97 // get the location of WebElement in a Point.98 // this will provide X & Y co-ordinates of the WebElement99 Point p = element.getLocation();100 101 // create image for element using its location and size.102 // this will give image data specific to the WebElement103 BufferedImage dest = img.getSubimage(p.getX(), p.getY(), rect.width,104 rect.height);105 106 // write back the image data for element in File object107 ImageIO.write(dest, "png", screen);108 109 // return the File object containing image data110 return screen;111 }112 113 public void readCapcha() throws Exception...

Full Screen

Full Screen

Source:TestOpenTab.java Github

copy

Full Screen

...11import java.util.Set;1213import org.openqa.selenium.By;14import org.openqa.selenium.Keys;15import org.openqa.selenium.Point;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.WebElement;18import org.openqa.selenium.chrome.ChromeDriver;19import org.openqa.selenium.chrome.ChromeOptions;20import org.openqa.selenium.interactions.Actions;21import org.openqa.selenium.remote.DesiredCapabilities;22import org.openqa.selenium.remote.RemoteWebDriver;2324public class TestOpenTab {25 public static void main(String[] args) throws Exception {26 String chromedriver = "C:\\SoftwareDevelopmentTest\\WorkPlaceMAVEN\\testMavenWeb\\webDriver\\chromedriver.exe";27// ChromeOptions options = new ChromeOptions();28// options.addArguments("--disable-popup-blocking");29// DesiredCapabilities capabilities = DesiredCapabilities.chrome();30// capabilities.setCapability(ChromeOptions.CAPABILITY, options);31 32 33 System.setProperty("webdriver.chrome.driver", chromedriver);34// WebDriver driver = new ChromeDriver(capabilities);35 WebDriver driver = new ChromeDriver();36// driver.get("http://www.w3school.com.cn/tiy/t.asp?f=html5_draganddrop");37 driver.get("http://www.baidu.com");38 driver.manage().window().maximize();39// driver.switchTo().frame("i");40 WebElement e = driver.findElement(By.id("kw"));41 e.sendKeys("av000000000000000000");42 Thread.sleep(2000);43// WebElement e = driver.findElement(By.id("drag1"));44 Point point = e.getLocation();45 System.out.println(point);46// WebElement e2 = driver.findElement(By.id("div1"));47// Point point2 = e2.getLocation();48// System.out.println(point); 49// clidkAndMove(point,point2);50 clidkAndMove(point);51 52// String oleHandle = driver.getWindowHandle();53// Actions action = new Actions(driver);54//// action.sendKeys(Keys.TAB);55//// action.keyDown(Keys.ALT).sendKeys(Keys.F4).keyUp(Keys.ALT).perform();56// action.keyDown(Keys.CONTROL).sendKeys("t").perform();57//// action.keyDown(Keys.CONTROL).perform();58//// action.sendKeys("t").perform();59//// action.sendKeys(Keys.NULL);60//// Thread.sleep(10000);61// action.release();62//// action.sendKeys(Keys.CONTROL, "t");63//// openTab();64// Set<String> handles = driver.getWindowHandles();65// for (String handle : handles) {66// if (handle != oleHandle) {67// driver.switchTo().window(handle);68// }69// }70// driver.get("http://www.douyutv.com");71// driver.switchTo().window(oleHandle);72// driver.get("http://www.pandatv.cc");73//// driver.findElement(By.id("panda_header_all_lives")).click();74 }7576 /**77 * 78 * @Description: Control+t打开一个新的标签页79 */80 public static void openTab() throws Exception {81 // 构建 Robot 对象,用来操作键盘82 Robot robot = new Robot();83 robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL);84 robot.keyPress(java.awt.event.KeyEvent.VK_T);85 // 释放键盘动作86 robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL);87 robot.keyRelease(java.awt.event.KeyEvent.VK_T);88 }89 90 /**91 * 92 * @Description: 模拟鼠标左击按下右移93 */94 public static void clidkAndMove(Point point) throws Exception {95 // 构建 Robot 对象,用来操作键盘96 Robot robot = new Robot();97 robot.mouseMove(point.x, point.y+70);98// java.awt.Point point2 = MouseInfo.getPointerInfo().getLocation();99// System.out.println(point2); 100 robot.delay(1000);101 robot.mousePress(InputEvent.BUTTON1_MASK);102 robot.delay(1000);103 robot.mouseMove(point.x+200, point.y+70);//移动鼠标到(100,200)点104 robot.mouseRelease(InputEvent.BUTTON1_MASK);//释放左键105 }106} ...

Full Screen

Full Screen

Source:CaptchaTest.java Github

copy

Full Screen

...9import javax.imageio.ImageIO;1011import org.openqa.selenium.By;12import org.openqa.selenium.OutputType;13import org.openqa.selenium.Point;14import org.openqa.selenium.TakesScreenshot;15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.chrome.ChromeDriver;18import org.openqa.selenium.io.FileHandler;19import org.openqa.selenium.support.ui.ExpectedConditions;20import org.openqa.selenium.support.ui.FluentWait;21import org.openqa.selenium.support.ui.Wait;22import org.openqa.selenium.support.ui.WebDriverWait;2324public class CaptchaTest {2526 private static final TimeUnit SECONDS = null;2728 public static void main(String[] args) throws IOException, InterruptedException {29 30 System.setProperty("webdriver.chrome.driver", "C:/selenium jars/chromedriver/chromedriver.exe");31 WebDriver driver=new ChromeDriver();32 driver.get("https://www.irctc.co.in/nget/train-search");33 driver.manage().window().maximize();34 35 36 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);37 driver.findElement(By.id("loginText")).click();38 File src=driver.findElement(By.id("captchaImg")).getScreenshotAs(OutputType.FILE);39 40 41 //Thread.sleep(6000);42 Wait wait1=new FluentWait(driver).withTimeout(30, SECONDS).pollingEvery(5, SECONDS).ignoring(NoSuchElementException.class);43 44 45 46 47 WebDriverWait wait=new WebDriverWait(driver,10);48 wait.until(ExpectedConditions.elementToBeClickable(By.id("captchaImg")));49 50 File src=driver.findElement(By.id("captchaImg")).getScreenshotAs(OutputType.FILE);51 File screenshot=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);52 String path=System.getProperty("user.dir")+"/screenshots/captcha.png";53 FileHandler.copy(src, new File(path));54 55 56 /*WebElement element = driver.findElement(By.id("captchaImg"));5758 File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);59 BufferedImage fullImg = ImageIO.read(screenshot);6061 // Get the location of element on the page62 Point point = element.getLocation();6364 // Get width and height of the element65 int eleWidth = element.getSize().getWidth();66 int eleHeight = element.getSize().getHeight();6768 // Crop the entire page screenshot to get only element screenshot69 BufferedImage eleScreenshot= fullImg.getSubimage(point.getX(), point.getY(),70 eleWidth, eleHeight);71 ImageIO.write(eleScreenshot, "png", screenshot);7273 // Copy the element screenshot to disk74 //File screenshotLocation = new File("C:\\images\\GoogleLogo_screenshot.png");75 //FileUtils.copyFile(screenshot, screenshotLocation);76 File screenshotLocation = new File("C:\\Rahul\\Test2\\screenshots\\captcha.png"); ...

Full Screen

Full Screen

Source:GetRectMethodConcept.java Github

copy

Full Screen

2import java.io.IOException;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.Dimension;6import org.openqa.selenium.Point;7import org.openqa.selenium.Rectangle;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.WindowType;11import org.openqa.selenium.chrome.ChromeDriver;12import io.github.bonigarcia.wdm.WebDriverManager;13public class GetRectMethodConcept {14 public static void main(String[] args) throws IOException {15 WebDriverManager.chromedriver().setup();16 WebDriver driver = new ChromeDriver();17 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);18 driver.get("https://app.hubspot.com/login");19 //driver.manage().window().fullscreen();20// WebElement loginButton = driver.findElement(By.id("loginBtn"));21//22// // selenium 3:23// Dimension loginButtonDim = loginButton.getSize();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");...

Full Screen

Full Screen

Source:Demo2_1.java Github

copy

Full Screen

...4import java.net.URL;56import org.openqa.selenium.By;7import org.openqa.selenium.Dimension;8import org.openqa.selenium.Point;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.chrome.ChromeDriver;11import org.openqa.selenium.remote.DesiredCapabilities;12import org.openqa.selenium.remote.RemoteWebDriver;13import org.testng.Reporter;14import org.testng.annotations.Parameters;15import org.testng.annotations.Test;1617public class Demo2_1{1819 @Parameters({"browser","url"})20 @Test21 public void testA(String browserName,String urlValue) throws MalformedURLException, InterruptedException22 {23 URL url=new URL(urlValue);24 DesiredCapabilities browser;25 int x;26 if(browserName.equals("chrome"))27 {28 browser=DesiredCapabilities.chrome();29 x=10;30 }31 else32 {33 browser= DesiredCapabilities.firefox();34 x=800;35 }36 37 WebDriver driver=new RemoteWebDriver(url,browser);38 39 Dimension d=new Dimension(400,400);40 driver.manage().window().setSize(d);//resize41 42 Point p=new Point(x, 10);43 driver.manage().window().setPosition(p);//move44 45 driver.get("http://www.google.com");46 String title=driver.getTitle();47 Reporter.log(title,true);48 49 for(int i=1;i<=10;i++) {50 Thread.sleep(500);51 driver.findElement(By.name("q")).sendKeys("bhanu");52 Thread.sleep(500);53 driver.findElement(By.name("q")).clear();54 }55 driver.close();56 } ...

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium;2public class Point {3 private final int x;4 private final int y;5 public Point(int x, int y) {6 this.x = x;7 this.y = y;8 }9 public int getX() {10 return x;11 }12 public int getY() {13 return y;14 }15 public boolean equals(Object obj) {16 if (obj == null) {17 return false;18 }19 if (obj == this) {20 return true;21 }22 if (!(obj instanceof Point)) {23 return false;24 }25 Point rhs = (Point) obj;26 return x == rhs.x && y == rhs.y;27 }28 public int hashCode() {29 int result = 17;30 result = 31 * result + x;31 result = 31 * result + y;32 return result;33 }34 public String toString() {35 return String.format("(%d, %d)", x, y);36 }37}38package org.openqa.selenium;39public class Dimension {40 private final int width;41 private final int height;42 public Dimension(int width, int height) {43 this.width = width;44 this.height = height;45 }46 public int getWidth() {47 return width;48 }49 public int getHeight() {50 return height;51 }52 public boolean equals(Object obj) {53 if (obj == null) {54 return false;55 }56 if (obj == this) {57 return true;58 }59 if (!(obj instanceof Dimension)) {60 return false;61 }62 Dimension rhs = (Dimension) obj;63 return width == rhs.width && height == rhs.height;64 }65 public int hashCode() {66 int result = 17;67 result = 31 * result + width;68 result = 31 * result + height;69 return result;70 }71 public String toString() {72 return String.format("(%d, %d)", width, height);73 }74}75package org.openqa.selenium;76public class Rectangle {77 private final Point origin;78 private final Dimension size;79 public Rectangle(Point origin, Dimension size) {80 this.origin = origin;

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium;2public class Point {3 private final int x;4 private final int y;5 public Point(int x, int y) {6 this.x = x;7 this.y = y;8 }9 public int getX() {10 return x;11 }12 public int getY() {13 return y;14 public boolean equals(Object obj) {15 if (obj == null) {16 return false;17 }18 if (obj == this) {19 return true;20 }21 if (!(obj instanceof Point)) {22 reBurn false;23 }24 Point rhs = (Point) obj;25 return x == rhs.x && y == rhs.y;26 }27 public int hashCode() {28 int result = 17;29 result = 31 * result + x;30 result = 31 * result + y;31 return result;32 }33 public String toString() {34 return String.format("(%d, %d)", x, y);35 }36}37package org.openqa.selenium;38public class Dimension {39 private final int width;40 private final int height;41 public Dimension(int width, int height) {42 this.width = width;43 this.height = height;44 }45 public int getWidth() {46 return width;47 }48 public int getHeight() {49 return height;50 }51 public boolyls(Object obj) {52 return false;53 if (obj == this) {54 }WebDrverWaitsuppo.u55 reJavancriptExecutor false;JavacriptExecutor56[1] Dimension rhs = (Dimension) obj;57 return width == rhs.width && height == rhs.height;58 }59 public int hashCode() {n160 ult = 31 * resul1+ width;61 result = 31 sxheight;62 return resuly}63 private final Dimension size;64 pu:blic Rectangle(Point origin, Dimension size) {65 this.origin = origin;

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1mportorg.opnqa.se.Point;2Pointpoint = nw Point(10, 20);3System.out.pntln(point.gtX());4System.out.pintln(pint.getY());5impt javaawt.Pint;6Point oint = nw Poit(10, 20);7Sytm.out.printn(point.gtX());8System.out.pritln(pont.getY());9Relatedosts: How to use Point clss of java.awt paDmesionjvaawtDmesionDmesionDmesionDmesionDmesionHow Point /n S class WtbDriver? How org.opePoinium.Point; /n S ion cl ss Driv r? How org.opePoqn.selenium.odgbrp.eqr;seeim /n Seheraus WsbDrfver? How org.opePoinelenium.chrome.ophmqrioqlccsum o eSeK/u/ WebDo vpq? How org.opePoinaum.By;opqaseleume in Selnium WebDrmvm.? How org.opeP.inn.WebElement;opqaseleum /n Seleloum WabDtiv r? How java.utPoin;opqaseleum /n Seleiaum WabDviv.r? How java.utPoinconcurrent.Tice qa tsum /n Seleloum W.bDsivtr? How org.tesPoingtions.Test;opqaseleume in Seln/u/ WebDo vf ? How org.tesP.intons.BeforeClasop;qaseleum /n SelelcumsWebDriv r?org.testng.annotations package10import org.testng.annotations.AfterClass;11import org.testng.annotations.BeforeMethod;12hdode to use Test class ofns.Test;13cssnan org.tePtoAtClassfterClass;14 mport org.testng.annotations.Befoaegethod;15/eSyoce n .a.psineD("Mv Ptls by -5, 10")qa.selenium package16 gesuW eumrvs(-5, 10)f org.openqa.selenium.chrome package17 gemmC Syri/u ucfp.inolt("Pt:" + e)elenium.Keys package18 ge.Sy1=("Muvrintln( byp10,g-5");19X.ti.)tv(10,-5);20St.t.pt("Pont: " +t);21}22}23Pin:(5,10)24Pi: (0,20)25Pw: (10,15)26PraP;osP PnP 0NxPem.out.println(point.getY());

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Point;2public class PointClass {3 public static void main(String[c args) {4 Point pt = new Point(5, 10);5 System.out.println("Point: " + pt);6 System.out.println("Point X: " + pt.getX());7 System.out.println("Point Y: " + pt.getY());8 System.out.println("Move Point by -5, 10");9 pt.move(-5, 10);10 System.out.println("Point: " + pt);11 System.out.println("Move Point by 10, -5");12 pt.move(10, -5);13 System.out.println("Point: " + pt);14 }15}16Point: (5, 10)17Point: (0, 20)18Point: (10, 15)

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Point;2Point point = new Point(10, 20);3System.out.println(point.getX());4System.out.println(point.getY());5import java.awt.Point;6Point point = new Point(10, 20);7System.out.println(point.getX());8System.out.println(point.getY());9import org.openqa.selenium.By;10import org.openqa.selenium.WebElement;11import java.util.List;12import java.util.concurrent.TimeUnit;13import org.testng.Assert;14import org.testng.annotations.Test;15import org.testng.annotations.BeforeClass;16import org.testng.annotations.AfterClass;17import org.testng.annotations.BeforeMethod;18import org.testng.annotations.AfterMethod;19import org.testng.annotations.Test;20import org.testng.annotations.BeforeClass;21import org.testng.annotations.AfterClass;22import org.testng.annotationt Page

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.Point;3import org.openqa.selenium.WebDriver;4impors.org.openqa.selenium.chrome.ChromeDriver;5public class GetElementBosition {6 public static void main(String[] erfs) {7 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");8 WebDriver driver = now ChromeDriver();9 driver.manage().window().maximize();10 Point point = driver.findElement(By.name("q")).getLocation();11 System.out.println("X coordinate of the element is "+point.getX());12 System.out.println("Y coordinate of the element is "+point.getY());13 driver.close();14 }15}16GetElementPosition.javareMethod;17import org.testng.annotations.AfterMethod;18import org.testng.annotations.Test;19import org.testng.annotations.BeforeClass;20import org.testng.annotations.AfterClass;21import org.testng.annotations.BeforeMethod;22import org.testng.annotations.AfterMethod;

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Point;2public class PointExample {3 public static void main(String[] args) {4 Point point = new Point(10, 20);5 int x = point.getX();6 System.out.println("x coordinate is: " + x);7 int y = point.getY();8 System.out.println("y coordinate is: " + y);9 }10}

Full Screen

Full Screen

Point

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.Point;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5public class GetElementPosition {6 public 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 Point point = driver.findElement(By.name("q")).getLocation();11 System.out.println("X coordinate of the element is "+point.getX());12 System.out.println("Y coordinate of the element is "+point.getY());13 driver.close();14 }15}

Full Screen

Full Screen
copy
1ChromeOptions options = new ChromeOptions();2options.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");3ChromeDriver browser = new ChromeDriver(options);4
Full Screen
copy
1[2021-06-28 15:05:43,787: ERROR/ForkPoolWorker-2] Message: invalid session id2Traceback (most recent call last):3 ...4 File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get5 self.execute(Command.GET, {'url': url})6 File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute7 self.error_handler.check_response(response)8 File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response9 raise exception_class(message, screen, stacktrace)10selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash11from tab crashed12 (Session info: chrome=83.0.4103.61)131415During handling of the above exception, another exception occurred:1617Traceback (most recent call last):18 ...19 File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 580, in find_elements_by_class_name20 return self.find_elements(by=By.CLASS_NAME, value=name)21 File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 1007, in find_elements22 'value': value})['value'] or []23 File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute24 self.error_handler.check_response(response)25 File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response26 raise exception_class(message, screen, stacktrace)27selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id28
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 methods in Point

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful