How to use Interface WebDriver.Window class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.Interface WebDriver.Window

Source:InteractionLayer.java Github

copy

Full Screen

1package taf;23import java.io.File;4import java.io.IOException;5import java.util.List;6import java.util.concurrent.TimeUnit;78import org.apache.commons.io.FileUtils;9import org.openqa.selenium.By;10import org.openqa.selenium.Dimension;11import org.openqa.selenium.NoSuchElementException;12import org.openqa.selenium.OutputType;13import org.openqa.selenium.TakesScreenshot;14import org.openqa.selenium.WebDriver;15import org.openqa.selenium.WebElement;16import org.openqa.selenium.chrome.*;17import org.openqa.selenium.firefox.*;18import org.openqa.selenium.remote.Augmenter;19import org.openqa.selenium.support.ui.ExpectedConditions;20import org.openqa.selenium.support.ui.Select;21import org.openqa.selenium.support.ui.WebDriverWait;22//import java.sql.SQLException;23//import java.util.ArrayList;24//import java.util.Iterator;25/**26 * 27 */2829/**30 * @author macdonc31 *32 */33public class InteractionLayer {34 35 public static String stepSuccess;36 public String executionDetail = "";37 public static String fieldDesc;38 public static String fieldInputVal;39 public static String fieldType;40 public static int globalWait;41 public static WebDriver driver;42 public static String osSystem = System.getProperty("os.name");43 public static String Browser;44 //public static WebDriver;45 //static WebDriver driver;46// public static void newDriverCreate(){47// 48 //public static WebDriver driver = new FirefoxDriver();49// //* @param args50// } 51 52 public static void main(String[] args) {53 // TODO Auto-generated method stub54 //String navSuccess = "true";55 //selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/");56 //WebDriver driver = new FirefoxDriver();57 58 }5960 //public void setUp() 61 62 //}63 64 public static String browserInvoke(String browser) throws Exception {65 // launch the browser, create the driver object66 67 System.out.println("Globally declared browser type: " + Startup.BROWSER);68 69 switch (browser){70 case "BROWSER":71 browser = Startup.BROWSER; // get globally defined browser class.72 System.out.println("Globally declared browser type: " + browser);73 break;74 default:75 break;76 }77 78 Browser = browser.toLowerCase();79 80 if (driver != null){ // does an active driver instance already exist?81 //driver.close();82 driver.quit();83 }84 85 System.out.println(osSystem);86 87 switch (Browser){88 case "chrome": 89 switch (osSystem){90 case "Mac OS X": 91 System.setProperty("webdriver.chrome.driver", "//chromedriver//chromedriver"); // need to document this92 ChromeOptions options = new ChromeOptions();93 options.addArguments("--start-maximized");94 driver = new ChromeDriver(options);95 //driver = new ChromeDriver();96 break;97 default:98 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver\\chromedriver.exe"); // need to document this99 driver = new ChromeDriver();100 break;101 }102 break;103 default: // default to firefox.104 switch (osSystem){105 case "Mac OS X":106 System.setProperty("webdriver.gecko.driver", "//geckodriver//geckodriver"); // need to document this107 driver = new FirefoxDriver();108 break;109 default:110 System.setProperty("webdriver.gecko.driver", "C:\\GeckoDriver\\geckodriver.exe"); // need to document this111 driver = new FirefoxDriver();112 break;113 }114 115 break;116 117 }118 119 driver.manage().window().maximize();120 121 System.out.println(driver);122 123 124 //String driverString = 125 126 //ActorLibrary.scenarioInfoContainer.put("driver",driver);127 128 stepSuccess = "pass";129 130 //WebDriver driver =new FirefoxDriver();131 132 //String baseUrl = ActorLibrary.globalInfoContainer.get("BASE_URL");133 //driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);134 //driver.135 136 // try and catch? What if we can't launch for some reason?137 //driver.get(ActorLibrary.globalInfoContainer.get("target_url"));138 return stepSuccess;139 }140 141 public static void killBrowser(){142 143 if (driver != null){144 driver.quit();145 }146 147 //java.util.Set<String> windowIterator = driver.getWindowHandles();148 //Iterator<String> iter = windowIterator.iterator();149 //System.out.println(windowIterator);150 //System.out.println("number of windows to close = " + windowIterator.size());151 152 153 //driver.Dispose();154 //tearDown();155 //driver.quit(); // quit actually kills the session. need a better method!156 }157 158 public static void maximiseBrowser(){159 //var window = new webdriver.Webdriver.Window(driver);160 if (driver == null){161 return; //"fail";162 }163 164 driver.manage().window().maximize();165 }166 167 168 public static String objectClick(){169 170 // else {171 if (driver == null){172 return "fail";173 }174 175 String seekFlag = isElementPresent(OperationStepProcess.navTarget);176 177 if (seekFlag != "pass"){178 return seekFlag;179 }180 //}181 //findAllElementsOnPage("//*[@class='img' or @class='input']"); // we'll revisit this.182 //findAllElementsOnPage("//input");183 184 //findAllElementsOnPage("//img");185 186 //findAllElementsOnPage("img");187 188 //findAllElementsOnPage("alt=");189 190 // throws?191 WebDriverWait wait = new WebDriverWait(driver,10);192 //wait.Until(ExpectedConditions.elementToBeClickable(By.xpath (OperationStepProcess.navTarget)));193 194 driver.findElement(By.xpath (OperationStepProcess.navTarget)).click();195 196 return seekFlag;197 198 }199 200 public static String sendValueToField(String xpathDesc, String value){201 //int waitTimeGlobal = 30000;202 String inputSuccess = "pass";203 204 fieldDesc = xpathDesc;205 fieldInputVal = value;206 207 // chop up any meta info (radiobuttons, for example).208 cleanAndDetermine();209 210 String seekFlag = isElementPresent(fieldDesc);211 212 if (seekFlag != "pass"){213 return seekFlag;214 }215 216 sendValueToField();217 218 System.out.println("field populated:" + fieldDesc + ", value: " + fieldInputVal);219 220 return inputSuccess;221 }222 223 public static void cleanAndDetermine(){ // assert the type.224 225 // reset the type.226 fieldType = null; // fieldType is the field eventually used to determine behaviour.227 228 if (OperationStepProcess.declaredFieldType != null){ // has a field type already been declared? If so, use that.229 fieldType = OperationStepProcess.declaredFieldType;230 } else { // use the 'old' ;; meta functionality (i.e. field type included in field name string231 String[] fieldMeta = fieldDesc.split(";;", 2);232 // do we have field meta info?233 int metaIndicator = fieldMeta.length;234 235 if (metaIndicator > 1){236 System.out.println ("field meta detected:" + fieldMeta);237 fieldDesc = fieldMeta[0];238 fieldType = fieldMeta[1];239 }240 241 }242 243 244 switch (fieldType){245 case "radiobutton":246 System.out.println("radio button field input triggered.");247 radiobuttonHandling();248 return;249 //break;250 case "select":251 System.out.println("select field input triggered.");252 return;253 default:254 fieldType = "edit";255 return;256 //break;257 }258 259 260 261 // else, it's an edit field.262 //fieldType = "edit";263 264 265 }266 267 public static String isElementPresent(String desc){ // pass in the xpath description268 // is field present269 270 if (driver == null){271 return "fail";272 }273 274 275 stepSuccess = "pass";276 //WebDriverWait wait = new WebDriverWait(driver, globalWait);277 //WebDriverWait wait = new WebDriverWait(driver, 1);278 279 WebElement element = null;280 int totalWait = 0;281 int globalWaitMilli = (globalWait*1000);282 283 long startStamp = System.currentTimeMillis();284 System.out.println("sync start: "+ startStamp);285 long timeoutMilliPoint = (startStamp+globalWaitMilli);286 287 288 while (startStamp <= timeoutMilliPoint){289 290 //try{291 while (element == null){292 int navOptSize = OperationStepProcess.navTargetOptions.size();293 int navOpt;294 //String elementScanResult;295 296 if (navOptSize > 0){297 //FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver) // we are checking for more than one wait element.298 //.withTimeout(0, TimeUnit.SECONDS) // one second between scans. 299 //.pollingEvery(0, TimeUnit.SECONDS)300 //.ignoring(NoSuchElementException.class);301 302 //WebDriverWait wait = new WebDriverWait(driver, 0);303 304 305 for (navOpt = 0; navOpt < navOptSize; navOpt++){306 desc = OperationStepProcess.navTargetOptions.get(navOpt);307 System.out.println("alternate gui desc " + navOpt + " of " + navOptSize + " = " + desc);308 309 if (desc.length() < 3){310 stepSuccess = "fail";311 return "fail";312 }313 314 try{315 //element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(desc)));316 //driver.manage().timeouts().implicitlyWait(100,TimeUnit.MILLISECONDS);317 //driver.manage().timeouts().318 List <WebElement> elementList = driver.findElements(By.xpath(desc));319 320 //driver.manage().timeouts().implicitlyWait(globalWait,TimeUnit.MILLISECONDS);321 322 driver.manage().timeouts().implicitlyWait(globalWaitMilli, null);323 324 if (elementList.size() > 0){325 System.out.println("web element " + desc + "located.");326 OperationStepProcess.navTargetOptions.clear();327 OperationStepProcess.navTarget = desc;328 329 long currentStamp = System.currentTimeMillis();330 long elapsedTime = currentStamp-startStamp;331 double elapsedTimeInSeconds = elapsedTime/1000;332 System.out.println("sync complete, object located in "+ elapsedTimeInSeconds);333 334 return stepSuccess;335 }336 337 338 } catch (NoSuchElementException e) {339 // TODO Auto-generated catch block340 stepSuccess = "false";341 e.printStackTrace();342 343 //System.out.println("web element " + desc + "not found within specified time limit.");344 //return navSuccess;345 } 346 347 348 try {349 Thread.sleep(10);350 //totalWait++;351 352 long currentStamp = System.currentTimeMillis();353 354 //if (totalWait == (globalWait*100)){ // no sign of the element we are searching for. quit.355 if (currentStamp > timeoutMilliPoint){ 356 stepSuccess = "false";357 OperationStepProcess.navTargetOptions.clear();358 359 long elapsedTime = currentStamp-startStamp;360 double elapsedTimeInSeconds = elapsedTime/1000;361 System.out.println("sync failed: "+ elapsedTimeInSeconds);362 return "fail";363 }364 } catch (InterruptedException e) {365 // TODO Auto-generated catch block366 e.printStackTrace();367 }368 } 369 370 //OperationStepProcess.navTargetOptions = ;371 } else {372 373 374 //WebDriverWait wait = new WebDriverWait(driver, globalWait);375 376 //element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(desc)));377 try{378 //driver.manage().timeouts().implicitlyWait(globalWait,TimeUnit.MILLISECONDS);379 380 driver.manage().timeouts().implicitlyWait(globalWaitMilli,TimeUnit.MILLISECONDS);381 382 List <WebElement> elementList = driver.findElements(By.xpath(desc));383 384 if (elementList.size() > 0){385 stepSuccess = "pass";386 OperationStepProcess.navTargetOptions.clear();387 return "pass";388 }389 390 if (elementList.size() == 0){391 System.out.println("web element " + desc + "not found.");392 stepSuccess = "fail";393 //OperationStepProcess.navTargetOptions.clear();394 //OperationStepProcess.navTarget = desc;395 return "fail";396 }397 398 } catch (NoSuchElementException e) {399 // TODO Auto-generated catch block400 stepSuccess = "fail";401 e.printStackTrace();402 OperationStepProcess.navTargetOptions.clear();403 return "fail";404 //System.out.println("web element " + desc + "not found within specified time limit.");405 //return navSuccess;406 } 407 408 409 }410 //driver.findElement(By.xpath (desc));411 System.out.println (element);412 };413 414 415 416417 //catch}418 System.out.println("web element " + desc + "located.");419 return "pass";420 421 }422 return "pass";423 424 } // end of function425 426 public static void radiobuttonHandling(){427 428 String explicitOpt = specificItemCheck();429 430 String option = "";431 String[] fieldOptionSplit = fieldDesc.split(":", 2); // for re-assembly432 String selector = fieldOptionSplit[0];433 434 switch (fieldInputVal.toUpperCase()){435 case "0":436 option = ":0']";437 break;438 case "1":439 option = ":1']";440 break;441 case "TRUE":442 option = ":0']";443 break;444 case "FALSE":445 option = ":1']";446 break;447 case "Y":448 option = ":0']";449 break;450 case "N":451 option = ":1']";452 break;453 default:454 option = ":" + explicitOpt + "']";455 break;456 }457 458 459 fieldDesc = selector + option; // re-assign value.460 461 System.out.println("radiobutton processing. Input value = " + fieldInputVal + " = " + fieldDesc);462 463 464 }465 466 public static void sendValueToField (){467 468 469 try{470 switch(fieldType){471 case "radiobutton":472 driver.findElement(By.xpath (fieldDesc)).click();473 break;474 case "edit":475 driver.findElement(By.xpath(fieldDesc)).clear(); 476 driver.findElement(By.xpath (fieldDesc)).sendKeys(fieldInputVal);477 break;478 case "select":479 //driver.findElement(By.id(fieldDesc)).click();480 481 System.out.println("windows list select");482 driver.findElement(By.xpath(fieldDesc)).click();483 try {484 Thread.sleep(1000);485 } catch (InterruptedException e) {486 // TODO Auto-generated catch block487 e.printStackTrace();488 }489 490 switch (osSystem){491 case "Mac OS X": 492 // need to document this493 //Thread.sleep(1000);494 new Select(driver.findElement(By.xpath(fieldDesc))).selectByVisibleText(fieldInputVal);495 break;496 default:497 System.out.println("windows list select");498 driver.findElement(By.id(fieldDesc)).click();499 driver.findElement(By.id(fieldDesc)).sendKeys(fieldInputVal);500 break; 501 }502 503 break;504 default:505 driver.findElement(By.xpath (fieldDesc)).sendKeys(fieldInputVal);506 break;507 508 509 }510 511 } catch (NoSuchElementException e) {512 // TODO Auto-generated catch block513 e.printStackTrace();514 }515 516 517 518 }519 520 public static void findAllElementsOnPage(String elementClass){521 522 // //input523 // //img524 525 System.out.println("fail point check");526 527 List<WebElement> elements = driver.findElements(By.xpath(elementClass)); 528 529 //List<WebElement> elements = driver.findElements(By.xpath("//*[@class='img' or @class='input']"));530 531 //List<WebElement> elements = driver.findElements(By.xpath("//img*"));532 533 //List<WebElement> elements2 = driver.findElements(By.xpath("//*[@class='input']"));534 535 536 //System.out.println("number of elements detected for" + elementClass + " = " + elements.size());537 538 for(WebElement ele : elements){539 String elementText = ele.getText();540 int hashCheck = elementText.hashCode();541 if (hashCheck != 0){542 543 System.out.println(ele.getText());544 //System.out.println(ele.getClass());545 System.out.println("Class Name:" + (ele.getAttribute("className")));546 System.out.println("ID: " + (ele.getAttribute("id")));547 System.out.println("Title: " + (ele.getAttribute("title")));548 System.out.println("Name: " + (ele.getAttribute("name")));549 System.out.println("Class: " + (ele.getAttribute("class")));550 //System.out.println(ele.getAttribute("title")));551 //System.out.println(ele.getAlt());552 //System.out.println(ele.get());553 //System.out.println(ele.getClassName());554 }555 }556 557 System.out.println("scan complete");558 559 }560561 public static String specificItemCheck(){562 563 if (fieldInputVal.matches("(.*)specificitem(.*)") == true){564 String[] opt = fieldInputVal.split(" ");565 return opt[1];566 }567 568 return "";569 }570571 public static String obtainHTMLFromAUT(String xpath){572 String actualTextOutput = null;573 574 575 try{576 //driver.highlightElement(By.xpath(xpath));577 //WebElement elem = driver.findElement(By.xpath(xpath));578 //elem.highlight();579 //actualTextOutput = elem.getAttribute("innerHTML");580 actualTextOutput = driver.getPageSource();581 582 583 } catch (NoSuchElementException e) {584 // TODO Auto-generated catch block585 e.printStackTrace();586 }587 588 return actualTextOutput;589 }590 591 public static String obtainTextFromElement(String xpath){592 String actualTextOutput = null;593 String findObj = null;594 595 try{596 //driver.highlightElement(By.xpath(xpath));597 //WebElement elem = driver.findElement(By.xpath(xpath));598 //elem.highlight();599 //actualTextOutput = elem.getAttribute("innerHTML");600 601 findObj = isElementPresent(xpath);602 603 if (findObj != "pass"){604 actualTextOutput = "element not found!";605 System.out.println(actualTextOutput);606 return actualTextOutput;607 }608 609 //if ()610 611 actualTextOutput = driver.findElement(By.xpath(xpath)).getText();612 //unicode checking613 actualTextOutput = findUnicodeChars(actualTextOutput);614 615 } catch (NoSuchElementException e) {616 // TODO Auto-generated catch block617 e.printStackTrace();618 actualTextOutput = "element not found!";619 return actualTextOutput;620 }621 622 return actualTextOutput;623 }624 625 public static Boolean findTextInString(String xpath, String arrRef){626 627 Boolean isFound = false;628 //if (xpath == "null"){629 //xpath = "//div[@id='main']"; // if we haven't specified an element, pull out everything from 'main'.630 //}631 632 String seekText = ActorLibrary.scenarioInfoContainer.get(arrRef);633 634 if (seekText == null){635 Verification.vpDetail = "nothing in scenario info hashmap for element " + arrRef + ", value has not been loaded.";636 System.out.println(Verification.vpDetail);637 638 return isFound;639 640 }641 642 643 String entireText = InteractionLayer.obtainTextFromElement(xpath);644 645 try {646 isFound = entireText.toLowerCase().contains(seekText.toLowerCase());647 } catch (org.openqa.selenium.NoSuchElementException e){648 System.out.println(e);649 }650 651 return isFound;652 653 654 }655 656 657 public static void dumbWait(int milliseconds){658 659 System.out.println("dumb wait called for " + milliseconds + " milliseconds. Starting.....");660 try {661 Thread.sleep(milliseconds);662 } catch (InterruptedException e) {663 // TODO Auto-generated catch block664 e.printStackTrace();665 }666 System.out.println("dumb wait finished.");667 668 }669 670 public static void screenCapture(){671 672 String outputPath;673 674 if (driver == null){675 return; // a preparatory step has failed; nothing to capture676 }677 678 //public interface TakesScreenshot;679 680 //String timeStamp = Reporting.getTimeStampForFailCapture();681 682 try{683 WebDriver augmentedDriver = new Augmenter().augment(driver);684 File source = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);685 //outputPath = "./target/screenshots/fails/" + ActorLibrary.runName + "/" + ActorLibrary.scenarioIndex + "_" + ActorLibrary.operationalDataset +".png";686 outputPath = ActorLibrary.testDir + "/" + ActorLibrary.scenarioIndex + "_" + ActorLibrary.operationalDataset +".png";687 FileUtils.copyFile(source, new File(outputPath));688 689 ActorLibrary.failCaptureScreenshot = outputPath;690 691 ActorLibrary.failurePoint = ActorLibrary.failurePoint + " - image: " + ActorLibrary.failCaptureScreenshot;692 693 outputPath = null;694 695 } catch (IOException e){696 outputPath = "failed to capture screenshot: " + e.getMessage();697 698 }699 700 //File701 702 }703 704 public static String findUnicodeChars(String originalText){705 706 //int stringLen = originalText.length();707 //int pos;708 709 if (originalText == null){710 return originalText;711 }712 713 originalText = originalText.replace("\u2082", "subscript2");714 //System.out.println(originalText);715 716 originalText = originalText.replace("�", "subscript2");717 System.out.println(originalText);718 719 //String[] 720 721 //for (pos=0;pos<stringLen;pos++){722 723 724 725 //}726 727 return originalText;728 729 }730731 public static void makeDir(String dir){732 733 //parameterize this734 File theDir = new File(dir);735 736 if (!theDir.exists()){737 System.out.println("creating directory: " + ActorLibrary.runName);738 boolean result = false;739 740 try{741 theDir.mkdir();742 result = true;743 } catch (SecurityException se){744 745 }746 747 if (result){748 System.out.println("DIR created");749 }750 751 752 }753 754 }755756 public static String browserURLSelect(String navTarget) {757 // TODO Auto-generated method stub758 switch (navTarget){759 case "BASE_URL": // substitute value760 navTarget = Startup.BASE_URL;761 break;762 default: // url IS navTarget763 break;764 }765 766 driver.get(navTarget);767 driver.manage().window().maximize();768 //driver.manage().window().fullscreen();769 //driver.manage().window().setSize("1000","600");770 771 stepSuccess = "pass";772 return stepSuccess;773 }774 775} ...

Full Screen

Full Screen

Source:ElementHandler.java Github

copy

Full Screen

1package com.ui.automation.framework.pagefactory.web.interceptor;2import com.ui.automation.framework.cache.DriverCache;3import com.ui.automation.framework.cache.ElementCache;4import com.ui.automation.framework.cache.MethodCache;5import com.ui.automation.framework.webdriver.Alert;6import com.ui.automation.framework.webdriver.ScreenShot;7import com.ui.automation.framework.webdriver.Sleeper;8import com.ui.automation.framework.webdriver.Window;9import com.ui.automation.framework.pagefactory.web.Element;10import com.ui.automation.framework.pagefactory.WithTimeoutProcessor;11import io.appium.java_client.pagefactory.WithTimeout;12import lombok.extern.slf4j.Slf4j;13import org.openqa.selenium.WebDriver;14import org.openqa.selenium.WebElement;15import org.openqa.selenium.support.pagefactory.ElementLocator;16import java.lang.reflect.*;17import java.util.Arrays;18import java.util.List;19import static com.ui.automation.framework.pagefactory.web.ImplementedByProcessor.getImplementClass;20import static com.ui.automation.framework.pagefactory.web.ScrollIntoViewProcessor.getScrollIntoView;21/**22 * Replaces DefaultLocatingElementHandler. Simply opens it up to descendants of the WebElement interface, and other23 * mix-ins of WebElement and Locatable, etc. Saves the wrapping type for calling the constructor of the wrapped classes.24 */25@Slf4j26public class ElementHandler implements InvocationHandler {27 /**28 * The Alert.29 */30 protected final Alert alert;31 private final Window window;32 private final Sleeper sleeper;33 private final WebDriver driver;34 private final ElementLocator locator;35 private final Class<?> implementtingType;36 private final String logicElementName;37 private final Field field;38 /**39 * Generates a handler to retrieve the WebElement from a locator for a given WebElement interface descendant.40 *41 * @param interfaceType the interface type42 * @param locator the locator43 * @param field the field44 */45 public <T> ElementHandler(Class<T> interfaceType, ElementLocator locator, Field field) {46 this.driver = DriverCache.get();47 this.locator = locator;48 if (!Element.class.isAssignableFrom(interfaceType)) {49 throw new RuntimeException("interface not assignable to Element.");50 }51 this.implementtingType = getImplementClass(interfaceType);52 this.logicElementName = field.getName();53 this.field = field;54 this.alert = new Alert(driver);55 this.window = new Window(driver);56 this.sleeper = new Sleeper();57 }58 @Override59 public Object invoke(Object object, Method method, Object[] paras) throws Throwable {60 Element wapperElement = null;61 List<WebElement> elements = null;62 WebElement element = null;63 int previousWindowsCount = driver.getWindowHandles().size();64 long timeout = 0;65 if (field.isAnnotationPresent(WithTimeout.class)) {66 WithTimeout withTimeout = field.getAnnotation(WithTimeout.class);67 timeout = withTimeout.unit().toMillis(withTimeout.time());68 } else {69 timeout = WithTimeoutProcessor.getTimeOutOfFind(field, 1);70 }71 long currentTime = System.currentTimeMillis();72 long maxTime = System.currentTimeMillis() + timeout;73 while (currentTime < maxTime) {74 elements = locator.findElements();75 if (elements.size() > 1) {76 boolean isFound = false;77 for (WebElement e : elements) {78 if (e.isDisplayed()) {79 element = e;80 isFound = true;81 break;82 }83 }84 if (isFound) {85 break;86 }87 } else if (elements.size() == 1) {88 element = elements.get(0);89 if (element.isDisplayed()) {90 break;91 }92 }93 this.sleeper.sleep();94 currentTime = System.currentTimeMillis();95 }96 if (element == null) {97 if (!method.getName().equals("isDisplayed")) {98 log.error("the " + logicElementName99 + " element can't be found and the time(" + String.valueOf(timeout) + ") is out");100 throw new RuntimeException("the " + logicElementName101 + " element can't be found and the time(" + String.valueOf(timeout) + ") is out");102 } else {103 return false;104 }105 }106 if ("getWrappedElement".equals(method.getName())) {107 return element;108 }109 Constructor<?> cons = implementtingType.getConstructor(WebDriver.class, WebElement.class);110 Object obj = cons.newInstance(driver, element);111 try {112 wapperElement = (Element) obj;113 if (method.getName().equals("click") || method.getName().equals("sendKeys") || method.getName().equals("mouseOver")) {114 wapperElement.scrollIntoView(getScrollIntoView(field));115 this.sleeper.sleep(50);116 try {117 wapperElement.highLight();118 } catch (Exception ignored) {119 }120 ;121 this.sleeper.sleep(50);122 }123 Object ret = null;124 if (method.getName().equals("click")) {125 String currMethodName = MethodCache.getCurrentMethodName();126 ScreenShot.captureAction(driver, currMethodName, logicElementName);127 ret = method.invoke(obj, paras);128 ElementCache.set(element);129 log.info(logicElementName + " click");130 this.sleeper.sleep(500);131 if (driver.getWindowHandles().size() > previousWindowsCount) {132 this.window.selectLastOpenedWindow();133 }134 } else {135 if (paras != null) {136 log.info(logicElementName + " " + method.getName() + " " + Arrays.deepToString(paras));137 } else {138 log.info(logicElementName + " " + method.getName());139 }140 ret = method.invoke(obj, paras);141 this.sleeper.sleep(500);142 }143 return ret;144 } catch (InvocationTargetException e) {145 // Unwrap the underlying exception146 if (e.getCause().toString().contains("not clickable") || e.getCause().toString().contains("stale element reference") || e.getCause().toString().contains("StaleElementReferenceException")) {147 log.info(e.getCause().toString());148 this.sleeper.sleep(5000);149 wapperElement.click();150 this.sleeper.sleep(2000);151 return "action.click";152 } else {153 throw e.getCause();154 }155 }156 }157}...

Full Screen

Full Screen

Interface WebDriver.Window

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.chrome.ChromeOptions;4public class Window {5 public static void main(String[] args) throws InterruptedException {6 ChromeOptions options = new ChromeOptions();7 WebDriver driver = new ChromeDriver(options);8 Thread.sleep(5000);9 Thread.sleep(5000);10 Thread.sleep(5000);11 Dimension d = new Dimension(600,600);12 Thread.sleep(5000);13 driver.close();14 }15}

Full Screen

Full Screen

Interface WebDriver.Window

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.Dimension;4import org.openqa.selenium.Point;5import org.openqa.selenium.WindowType;6import org.openqa.selenium.WindowType;7public class WindowHandle {8 public static void main(String[] args) {9 System.setProperty("webdriver.chrome.driver","C:\\Users\\Dell\\Downloads\\chromedriver_win32\\chromedriver.exe");10 WebDriver driver = new ChromeDriver();11 driver.manage().window().newWindow(WindowType.TAB);12 }13}14import org.openqa.selenium.WebDriver;15import org.openqa.selenium.chrome.ChromeDriver;16import org.openqa.selenium.Dimension;17import org.openqa.selenium.Point;18import org.openqa.selenium.WindowType;19import org.openqa.selenium.WindowType;20import org.openqa.selenium.WebDriver.Navigation;21public class NavigationHandle {22 public static void main(String[] args) {23 System.setProperty("webdriver.chrome.driver","C:\\Users\\Dell\\Downloads\\chromedriver_win32\\chromedriver.exe");24 WebDriver driver = new ChromeDriver();25 driver.navigate().back();26 driver.navigate().forward();27 driver.navigate().refresh();28 driver.close();29 }30}31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.chrome.ChromeDriver;33import org.openqa.selenium.Dimension;34import org.openqa.selenium.Point;35import org.openqa.selenium.WindowType;36import org.openqa.selenium.WindowType;37import org.openqa.selenium.WebDriver.Navigation;38import org.openqa.selenium.WebDriver.Options;39public class OptionsHandle {40 public static void main(String[] args) {41 System.setProperty("webdriver.chrome.driver","C:\\Users\\Dell\\Downloads\\chromedriver_win32\\chromedriver.exe");42 WebDriver driver = new ChromeDriver();43 Options op = driver.manage();44 op.window().maximize();45 op.window().fullscreen();46 op.window().setSize(new Dimension(400,400));47 op.window().setPosition(new Point(100,100));48 driver.close();49 }50}

Full Screen

Full Screen

Interface WebDriver.Window

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3public class WindowHandle {4 public static void main(String[] args) {5 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Selenium\\chromedriver.exe");6 WebDriver driver = new ChromeDriver();7 driver.manage().window().maximize();8 String parent = driver.getWindowHandle();9 System.out.println(parent);10 driver.quit();11 }12}

Full Screen

Full Screen

Interface WebDriver.Window

Using AI Code Generation

copy

Full Screen

1package com.automationintesting.unit;2import org.junit.Test;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5public class WindowTest {6 public void windowTest() {7 WebDriver driver = new FirefoxDriver();8 driver.manage().window().maximize();9 driver.close();10 }11}12package com.automationintesting.unit;13import org.junit.Test;14import org.openqa.selenium.WebDriver;15import org.openqa.selenium.firefox.FirefoxDriver;16public class NavigationTest {17 public void navigationTest() {18 WebDriver driver = new FirefoxDriver();19 driver.close();20 }21}22package com.automationintesting.unit;23import org.junit.Test;24import org.openqa.selenium.WebDriver;25import org.openqa.selenium.firefox.FirefoxDriver;26public class OptionsTest {27 public void optionsTest() {28 WebDriver driver = new FirefoxDriver();29 driver.manage().deleteAllCookies();30 driver.manage().window().maximize();31 driver.close();32 }33}34package com.automationintesting.unit;35import org.junit.Test;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.firefox.FirefoxDriver;38public class TargetLocatorTest {39 public void targetLocatorTest() {40 WebDriver driver = new FirefoxDriver();41 driver.switchTo().frame("iframe");42 driver.close();43 }44}45package com.automationintesting.unit;46import org.junit.Test;47import org.openqa.selenium.WebDriver;48import org.openqa.selenium.firefox.FirefoxDriver;49public class TimeoutsTest {50 public void timeoutsTest() {51 WebDriver driver = new FirefoxDriver();52 driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);53 driver.close();54 }55}

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 methods in Interface-WebDriver.Window

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