Best Selenium code snippet using org.openqa.selenium.By.getJavascriptExecutor
Source:AppPage.java  
1package saleshandy.web.pom;2import java.awt.Toolkit;3import java.awt.datatransfer.StringSelection;4import java.io.File;5import java.io.InputStream;6import java.net.HttpURLConnection;7import java.net.MalformedURLException;8import java.net.URL;9import java.time.Duration;10import java.util.ArrayList;11import java.util.HashMap;12import java.util.List;13import java.util.NoSuchElementException;14import java.util.Set;15import java.util.concurrent.TimeUnit;16import org.apache.commons.io.IOUtils;17import org.apache.commons.lang.exception.ExceptionUtils;18import org.jsoup.Jsoup;19import org.jsoup.nodes.Document;20import org.openqa.selenium.Alert;21import org.openqa.selenium.By;22import org.openqa.selenium.Cookie;23import org.openqa.selenium.Dimension;24import org.openqa.selenium.ElementNotVisibleException;25import org.openqa.selenium.JavascriptExecutor;26import org.openqa.selenium.Point;27import org.openqa.selenium.StaleElementReferenceException;28import org.openqa.selenium.TimeoutException;29import org.openqa.selenium.WebDriver;30import org.openqa.selenium.WebDriverException;31import org.openqa.selenium.WebElement;32import org.openqa.selenium.interactions.Action;33import org.openqa.selenium.interactions.Actions;34import org.openqa.selenium.support.PageFactory;35import org.openqa.selenium.support.ui.ExpectedCondition;36import org.openqa.selenium.support.ui.ExpectedConditions;37import org.openqa.selenium.support.ui.FluentWait;38import org.openqa.selenium.support.ui.Select;39import org.openqa.selenium.support.ui.Wait;40import org.openqa.selenium.support.ui.WebDriverWait;41import org.slf4j.Logger;42import org.slf4j.LoggerFactory;43import org.testng.Assert;44import org.testng.TestListenerAdapter;45import com.google.common.base.Function;46import saleshandy.web.constants.WebDriverConstants;47import saleshandy.web.utility.BaseDriverHelper;48import saleshandy.web.utility.TakeScreenshot;49import saleshandy.web.utility.TakeScreenshotUtils;50public class AppPage extends TestListenerAdapter {51	protected static Logger logger = LoggerFactory.getLogger(AppPage.class.getName());52	protected WebDriver driver;53	JavascriptExecutor javaScriptExecutor;54	BaseDriverHelper baseDriverHelper = new BaseDriverHelper();55	enum ByTypes {56		INDEX, VALUE, TEXT57	}58	enum JavaScriptSelector {59		ID, CLASS, NAME, TAGNAME60	}61	public AppPage(WebDriver driver) {62		this.driver = driver;63		waitForPageLoadComplete();64		PageFactory.initElements(driver, this);65		String windowSize = System.getProperty("windowSize", "");66		if (windowSize.equals(""))67			maximizeWindow();68	}69	public void takeScreenShot(String fileName) {70		TakeScreenshot ts = new TakeScreenshotUtils(false, "", "", false);71		ts.captureScreenShot(driver, fileName);72	}73	public void takeScreenShot() {74		String fileName = WebDriverConstants.PATH_TO_BROWSER_SCREENSHOT_BASE;75		StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();76		fileName = fileName + stackTraceElements[2].getMethodName() + ".png";77		TakeScreenshot ts = new TakeScreenshotUtils(false, "", "", false);78		ts.captureScreenShot(driver, fileName);79	}80	public WebDriver getDriver() {81		return this.driver;82	}83	public void get(String url) {84		this.driver.get(url);85	}86	public String getCurrentUrl() {87		return this.driver.getCurrentUrl();88	}89	public void moveSlidderToOffSet(WebElement sliderHandle, int x, int y) {90		logger.info("X Offset : " + x + "Y Offset" + y);91//		int width = sliderHandle.getSize().width;92//		System.out.println(93//				width + "width" + sliderHandle.getSize().getWidth() + "height" + sliderHandle.getSize().getHeight()94//						+ "x" + sliderHandle.getLocation().getX() + "y" + sliderHandle.getLocation().getY());95//		System.out.println(sliderRange.getLocation().getY() + "c" + sliderRange.getLocation().getX() + "width"96//				+ sliderRange.getSize().width);97//		int xX = (sliderRange.getLocation().getY() - sliderRange.getLocation().getX()) / 100;98		Actions builder = new Actions(driver);99		Action dragAndDrop = builder.dragAndDropBy(sliderHandle, x, y).build();100		dragAndDrop.perform();101		sleep(500);102	}103	public void waitForURLToChange(String url) {104		final String currentURL = url;105		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))106				.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);107		wait.until(new ExpectedCondition<Boolean>() {108			public Boolean apply(WebDriver driver) {109				return !getCurrentUrl().equals(currentURL);110			}111		});112		return;113	}114	public void waitForURLContainingText(String urlText, int timeout) {115		final String expectedURL = urlText;116		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofSeconds(timeout))117				.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);118		wait.until(new ExpectedCondition<Boolean>() {119			public Boolean apply(WebDriver driver) {120				return getCurrentUrl().contains(expectedURL);121			}122		});123		return;124	}125	public Set<Cookie> getCookies() {126		return this.driver.manage().getCookies();127	}128	public HashMap<String, String> getCookiesHash() {129		Set<Cookie> cookies = getCookies();130		HashMap<String, String> cookieHash = new HashMap<String, String>();131		for (Cookie c : cookies) {132			cookieHash.put(c.getName(), c.getValue());133		}134		return cookieHash;135	}136	public void deleteCookies() {137		this.driver.manage().deleteAllCookies();138	}139	public String pageSource() {140		return this.driver.getPageSource();141	}142	public JavascriptExecutor getJavaScriptExecutor() {143		if (javaScriptExecutor == null)144			javaScriptExecutor = (JavascriptExecutor) driver;145		return javaScriptExecutor;146	}147	public boolean isElementPresent(By locator) {148		return this.driver.findElements(locator).size() == 0 ? false : true;149	}150	public boolean isElementPresent(WebElement element) {151		try {152			element.getAttribute("innerHTML");153		} catch (Exception ex) {154			return false;155		}156		return true;157	}158	public boolean isElementPresentAndDisplayed(WebElement element) {159		try {160			return isElementPresent(element) && element.isDisplayed();161		} catch (Exception ex) {162			return false;163		}164	}165	public boolean isElementPresentAndDisplayed(By xpath) {166		try {167			return isElementPresentAndDisplayed(this.driver.findElement(xpath));168		} catch (Exception ex) {169			return false;170		}171	}172	public Boolean isElementPresentInContainer(WebElement container, final By locator) {173		Boolean isElementPresent = false;174		if (container != null && container.findElements(locator).size() > 0)175			isElementPresent = true;176		return isElementPresent;177	}178	public ExpectedCondition<Boolean> isElementAttributeValuePresent(final WebElement identifier,179			final String attributeName, final String attributeValue) {180		return new ExpectedCondition<Boolean>() {181			public Boolean apply(WebDriver driver) {182				try {183					if (identifier.getAttribute(attributeName).contains(attributeValue)) {184						return true;185					}186				} catch (NullPointerException e) {187					return false;188				}189				return false;190			}191		};192	}193	public void waitForVisible(WebElement element) {194		WebDriverWait wait = new WebDriverWait(driver, WebDriverConstants.WAIT_FOR_VISIBILITY_TIMEOUT_IN_SEC);195		wait.until(ExpectedConditions.visibilityOf(element));196	}197	public void waitForVisible(WebElement element, Integer timeout) {198		WebDriverWait wait = new WebDriverWait(driver, timeout);199		wait.until(ExpectedConditions.visibilityOf(element));200	}201	public void waitForVisible(By locator) {202		WebDriverWait wait = new WebDriverWait(driver, WebDriverConstants.WAIT_FOR_VISIBILITY_TIMEOUT_IN_SEC);203		wait.until(ExpectedConditions.visibilityOfElementLocated(locator));204	}205	public void waitForSimpleCondition(final boolean waitCondition) {206		WebDriverWait wait = new WebDriverWait(driver, WebDriverConstants.WAIT_HALF_MIN);207		wait.until(new ExpectedCondition<Boolean>() {208			public Boolean apply(WebDriver driver) {209				return waitCondition;210			}211		});212	}213	public void waitForElementToBeEnabled(WebElement e) {214		final WebElement web = e;215		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))216				.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);217		wait.until(new ExpectedCondition<Boolean>() {218			public Boolean apply(WebDriver driver) {219				return web.isEnabled();220			}221		});222		return;223	}224	public void waitForElementToBeEnabled(final By locator) {225		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))226				.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);227		wait.until(new ExpectedCondition<Boolean>() {228			public Boolean apply(WebDriver driver) {229				return driver.findElement(locator).isEnabled();230			}231		});232		return;233	}234	public void waitForElementToContainText(WebElement e, String text) {235		waitForElementToBeEnabled(e);236		if (isElementPresentAndDisplayed(e)) {237			final String innerText = text;238			final WebElement element = e;239			Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))240					.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);241			wait.until(new ExpectedCondition<Boolean>() {242				public Boolean apply(WebDriver driver) {243					return element.getText().contains(innerText);244				}245			});246		}247		return;248	}249	public void waitForElementToContainText(By locator, String text) {250		waitForElementToBeEnabled(locator);251		if (isElementPresentAndDisplayed(locator)) {252			final String innerText = text;253			final By loc = locator;254			Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))255					.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);256			wait.until(new ExpectedCondition<Boolean>() {257				public Boolean apply(WebDriver driver) {258					return driver.findElement(loc).getText().contains(innerText);259				}260			});261		}262		return;263	}264	public void waitForPageLoadComplete() {265		waitForPageLoad(WebDriverConstants.MAX_TIMEOUT_PAGE_LOAD);266		waitForAJaxCompletion();267		return;268	}269	public void waitForPageLoadComplete(Integer timeout) {270		waitForPageLoad(timeout);271		return;272	}273	public void setBorderColour(WebElement element) {274		String js = "arguments[0].setAttribute('style','background: yellow; border: 2px solid red;";275		getJavaScriptExecutor().executeScript(js, element);276	}277	public void clearAndType(WebElement element, String text) {278		waitForElementToAppear(element);279		element.clear();280		element.sendKeys(text);281		sleep(500);282	}283	public void setTextUsingJS(WebElement element, String text) {284		getJavaScriptExecutor().executeScript("arguments[0].value=arguments[1]", element, text);285	}286	public void click(WebElement element) {287		waitForElementToAppear(element);288		element.click();289		sleep(1000);290	}291	public void clickUsingJS(WebElement element) {292		getJavaScriptExecutor().executeScript("arguments[0].click()", element);293	}294	public void hoverOverElementUsingJS(WebElement element) {295		String js = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover',true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";296		getJavaScriptExecutor().executeScript(js, element);297		sleep(1000);298	}299	public void clearAttrValueUsingElementID(String elementId) {300		String query = "document.getElementById('" + elementId + "').value = ''";301		getJavaScriptExecutor().executeScript(query);302	}303	public void clearFirstElementAttrValueUsingElementName(String elementName) {304		String query = "var eleList = document.getElementsByName('" + elementName + "'); eleList[0].value = ''";305		getJavaScriptExecutor().executeScript(query);306	}307	public void selectDropdown(WebElement element, String by, String value) {308		Select select = new Select(element);309		switch (ByTypes.valueOf(by.toUpperCase())) {310		case INDEX:311			select.selectByIndex(Integer.parseInt(value));312			break;313		case VALUE:314			select.selectByValue(value);315			break;316		case TEXT:317			select.selectByVisibleText(value);318			break;319		}320	}321	public void selectDropDownContainingText(WebElement element, String value) {322		Select select = new Select(element);323		List<String> allOptions = getAllSelectOptions(element);324		for (String s : allOptions) {325			if (s.contains(value)) {326				select.selectByVisibleText(s);327				break;328			}329		}330	}331	public WebElement fluentWaitByLocator(final By locator, int timeout) {332		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofSeconds(timeout))333				.pollingEvery(Duration.ofSeconds(3)).ignoring(NoSuchElementException.class);334		WebElement element = wait.until(new Function<WebDriver, WebElement>() {335			public WebElement apply(WebDriver driver) {336				return driver.findElement(locator);337			}338		});339		return element;340	}341	public void waitForPageLoad(int timeout) {342		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(timeout))343				.pollingEvery(Duration.ofSeconds(10)).ignoring(NoSuchElementException.class, WebDriverException.class);344		wait.until(new ExpectedCondition<Boolean>() {345			public Boolean apply(WebDriver driver) {346				String result = (String) getJavaScriptExecutor().executeScript("return document.readyState");347				if (result == null)348					return false;349				else350					return result.equals("complete");351			}352		});353		return;354	}355	public boolean verifyDropDownElements(WebElement drpdown, List<String> listExpected) {356		return getAllSelectOptions(drpdown).containsAll(listExpected);357	}358	public void scrollDown(String xVal, String yVal) {359		getJavaScriptExecutor().executeScript("scroll(" + xVal + ", " + yVal + ");");360	}361	public void maximizeWindow() {362		try {363			driver.manage().window().maximize();364		} catch (Exception e) {365			logger.debug("Exception while maximizing the window...");366			logger.debug(e.getMessage());367		}368	}369	public void windowResize(int hight, int width) {370		Dimension di = new Dimension(width, hight);371		driver.manage().window().setSize(di);372	}373	public void maximizeWindowToFullScreen() {374		Toolkit toolkit = Toolkit.getDefaultToolkit();375		int Width = (int) toolkit.getScreenSize().getWidth();376		int Height = (int) toolkit.getScreenSize().getHeight();377		Dimension screenResolution = new Dimension(Width, Height);378		logger.info("Setting the screen resolution as Height = " + Height + " and Width = " + Width);379		driver.manage().window().setSize(screenResolution);380	}381	public void dragAndDropElements(WebElement dragElem, WebElement dropElem) throws InterruptedException {382		Actions builder = new Actions(driver);383		Point p = dropElem.getLocation();384		scrollDown(String.valueOf(p.x), String.valueOf(p.y));385		Action dragAndDrop2 = builder.dragAndDropBy(dragElem, p.x, 0).build();386		dragAndDrop2.perform();387		Thread.sleep(5000);388		dragElem.click();389	}390	public String getVisibleTextOfElement(WebElement elem) {391		String visibleText = (String) getJavaScriptExecutor().executeScript(392				"var clone = $(arguments[0]).clone();" + "clone.appendTo('body').find(':hidden').remove();"393						+ "var text = clone.text();" + "clone.remove(); return text;",394				elem);395		visibleText = visibleText.replaceAll("\\s+", " ");396		return visibleText;397	}398	public Set<String> getWindowHandles() {399		return this.driver.getWindowHandles();400	}401	public String getWindowHandle() {402		return this.driver.getWindowHandle();403	}404	public void waitForWindowToClose(String windowId) {405		final String window = windowId;406		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(2))407				.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);408		wait.until(new ExpectedCondition<Boolean>() {409			public Boolean apply(WebDriver driver) {410				return !getWindowHandles().contains(window);411			}412		});413		return;414	}415	public void waitForNewWindow(int winCount) {416		final int count = winCount;417		Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))418				.pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);419		wait.until(new ExpectedCondition<Boolean>() {420			public Boolean apply(WebDriver driver) {421				return getWindowHandles().size() > count;422			}423		});424		return;425	}426	public boolean switchToNextWindowClosingCurrent() {427		boolean switchSuccess = false;428		List<String> windows = new ArrayList<String>(getWindowHandles());429		String currentWindow = getWindowHandle();430		if (windows.size() == 1) {431			return true;432		}433		for (int index = 0; index < windows.size(); index++) {434			if (currentWindow.equals(windows.get(index))) {435				this.driver.close();436				// Pass index, since the next window's index would've reduced by 1437				switchSuccess = switchToNthWindow(index);438				break;439			}440		}441		return switchSuccess;442	}443	public boolean closeAllWindowsExceptCurrent() {444		boolean switchSuccess = false;445		List<String> windows = new ArrayList<String>(getWindowHandles());446		String currentWindow = getWindowHandle();447		String handle;448		for (int index = 0; index < windows.size(); index++) {449			handle = windows.get(index);450			this.driver.switchTo().window(handle);451			if (!currentWindow.equals(handle)) {452				this.driver.close();453			}454		}455		this.driver.switchTo().window(currentWindow);456		return switchSuccess;457	}458	public boolean switchToNextWindow() {459		boolean switchSuccess = false;460		if (getWindowHandles().size() == 1) {461			logger.info("One window present..Waiting for new window to open");462			waitForNewWindow(1);463		}464		List<String> windows = new ArrayList<String>(getWindowHandles());465		String currentWindow = getWindowHandle();466		int count = windows.size();467		for (int index = 0; index < count; index++) {468			if (currentWindow.equals(windows.get(index))) {469				if (index == count - 1) {470					logger.info("switchToNextWindow() - Current window is last window..Switch not possible");471					break;472				}473				switchSuccess = switchToNthWindow(index + 1);474				break;475			}476		}477		return switchSuccess;478	}479	public boolean switchToNextWindow(int currentHandleCount) {480		boolean switchSuccess = false;481		if (getWindowHandles().size() == currentHandleCount) {482			logger.info("Waiting for new window to open");483			waitForNewWindow(currentHandleCount);484		}485		List<String> windows = new ArrayList<String>(getWindowHandles());486		String currentWindow = getWindowHandle();487		int count = windows.size();488		for (int index = 0; index < count; index++) {489			if (currentWindow.equals(windows.get(index))) {490				if (index == count - 1) {491					logger.info("switchToNextWindow() - Current window is last window..Switch not possible");492					break;493				}494				switchSuccess = switchToNthWindow(index + 1);495				break;496			}497		}498		return switchSuccess;499	}500	public boolean switchToPreviousWindow() {501		return switchToPreviousWindowClosingCurrent(false);502	}503	public boolean switchToPreviousWindowClosingCurrent(boolean close) {504		boolean switchSuccess = false;505		List<String> windows = new ArrayList<String>(getWindowHandles());506		String currentWindow = getWindowHandle();507		for (int index = 0; index < windows.size(); index++) {508			if (currentWindow.equals(windows.get(index))) {509				if (close)510					this.driver.close();511				switchSuccess = switchToNthWindow(index - 1);512				break;513			}514		}515		return switchSuccess;516	}517	public boolean switchToLastWindowClosingOthers() {518		List<String> windows = new ArrayList<String>(getWindowHandles());519		return switchToNthWindowClosingOthers(windows.size(), true);520	}521	public void switchToWindowClosingCurrent(String windowHandle) {522		this.driver.close();523		switchToWindow(windowHandle);524	}525	public boolean switchToNthWindowClosingOthers(int n, boolean close) {526		boolean switchSuccess = false;527		List<String> windows = new ArrayList<String>(getWindowHandles());528		if (windows.size() >= n) {529			if (close) {530				for (int index = 0; index < windows.size(); index++) {531					switchToWindow(windows.get(index));532					if (index != n) {533						this.driver.close();534					}535				}536			}537			switchToWindow(windows.get(n));538			switchSuccess = true;539		}540		return switchSuccess;541	}542	public boolean switchToNthWindow(int n) {543		return switchToNthWindowClosingOthers(n, false);544	}545	public void switchToWindow(String windowHandle) {546		sleep(500);547		this.driver.switchTo().window(windowHandle);548	}549	public boolean switchToWindowUsingTitle(String title) throws InterruptedException {550		String curWindow = this.driver.getWindowHandle();551		Set<String> windows = this.driver.getWindowHandles();552		if (!windows.isEmpty()) {553			for (String windowId : windows) {554				if (this.driver.switchTo().window(windowId).getTitle().equals(title)) {555					return true;556				} else {557					this.driver.switchTo().window(curWindow);558				}559			}560		}561		return false;562	}563	public void switchToWindowClosingOthers(String handle) {564		List<String> windows = new ArrayList<String>(getWindowHandles());565		for (String window : windows) {566			this.driver.switchTo().window(window);567			if (!window.equals(handle))568				this.driver.close();569		}570		this.driver.switchTo().window(handle);571	}572	public String getValueUsingJavaScript(String by, String ele) {573		String val = null;574		try {575			switch (JavaScriptSelector.valueOf(by.toUpperCase())) {576			case ID:577				val = (String) getJavaScriptExecutor()578						.executeScript("return document.getElementById('" + ele + "').value");579				break;580			case CLASS:581				val = (String) getJavaScriptExecutor()582						.executeScript("return document.getElementsByClassName('" + ele + "').value");583				break;584			case TAGNAME:585				val = (String) getJavaScriptExecutor()586						.executeScript("return document.getElementsByTagName('" + ele + "').value");587				break;588			case NAME:589				val = (String) getJavaScriptExecutor()590						.executeScript("return document.getElementsByName('" + ele + "').value");591				break;592			}593			return val;594		} catch (Exception e) {595			e.printStackTrace();596		}597		return val;598	}599	public void setvalueUsingJavaScript(String by, String ele, String val) {600		try {601			switch (JavaScriptSelector.valueOf(by.toUpperCase())) {602			case ID:603				System.out.println(("document.getElementById('" + ele + "').value = \"" + val + "\""));604				getJavaScriptExecutor().executeScript("document.getElementById('" + ele + "').value = \"" + val + "\"");605				break;606			case CLASS:607				getJavaScriptExecutor()608						.executeScript("document.getElementsByClassName('" + ele + "').value = \"" + val + "\"");609				break;610			case TAGNAME:611				getJavaScriptExecutor()612						.executeScript("document.getElementsByTagName('" + ele + "').value = \"" + val + "\"");613				break;614			case NAME:615				getJavaScriptExecutor()616						.executeScript("document.getElementsByName('" + ele + "').value = \"" + val + "\"");617				break;618			}619		} catch (Exception e) {620			e.printStackTrace();621		}622	}623	public void refresh() {624		this.driver.navigate().refresh();625		monkeyPatch();626	}627	public void closeWindow() {628		this.driver.close();629		sleep(500);630	}631	public List<String> getAllSelectOptions(WebElement drpdown) {632		Select s = new Select(drpdown);633		List<WebElement> list = s.getOptions();634		List<String> listNames = new ArrayList<String>(list.size());635		for (WebElement w : list)636			listNames.add(w.getText());637		return listNames;638	}639	public boolean hasSelectOption(WebElement drpDown, String value) {640		return getAllSelectOptions(drpDown).contains(value);641	}642	public void waitUntilDropdownIsLoaded(WebElement drpdown, final List<String> defaultOptions) {643		try {644			final WebElement dropdown = drpdown;645			ExpectedCondition<Boolean> isLoadingFalse = new ExpectedCondition<Boolean>() {646				public Boolean apply(WebDriver driver) {647					return (!getAllSelectOptions(dropdown).isEmpty()648							&& getAllSelectOptions(dropdown).size() != defaultOptions.size()649							&& !defaultOptions.containsAll(getAllSelectOptions(dropdown)));650				}651			};652			Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))653					.pollingEvery(Duration.ofSeconds(2)).ignoring(NoSuchElementException.class);654			wait.until(isLoadingFalse);655		} catch (Exception e) {656			logger.error(e.getMessage());657		}658	}659	protected Boolean validateURL(String url) {660		try {661			new URL(url);662		} catch (MalformedURLException e) {663			return false;664		}665		return true;666	}667	public void switchToDefaultContent() {668		this.driver.switchTo().defaultContent();669	}670	public void switchToFrame(String frameId) {671		this.driver.switchTo().frame(frameId);672	}673	public void switchToFrame(WebElement frame) {674		this.driver.switchTo().frame(frame);675	}676	public void switchToFrame(int index) {677		this.driver.switchTo().frame(index);678	}679	public String getAttribute(WebElement element, String attributeLocator) {680		return element.getAttribute(attributeLocator);681	}682	public String getAttribute(By byLocator, String attributeLocator) {683		return this.driver.findElement(byLocator).getAttribute(attributeLocator);684	}685	public void enterInput(WebElement element, String value) {686		String attr = null;687		waitForVisible(element);688		if ((attr = getAttribute(element, "type")) != null && !attr.equalsIgnoreCase("file"))689			element.clear();690		element.sendKeys(value);691	}692	public boolean isLinkPresent(String link) {693		String locator = "//a[text()='" + link + "']";694		return isElementPresent(By.xpath(locator));695	}696	public void clickOnLinkWithText(String linkText) {697		By locator = By.xpath("//a[text()='" + linkText + "']");698		if (isElementPresent(locator)) {699			driver.findElement(locator).click();700		}701	}702	public boolean checkValidityOfElement(WebElement e) {703		boolean res = (Boolean) getJavaScriptExecutor().executeScript("return arguments[0].checkValidity()", e);704		logger.info("check validity: " + res);705		return res;706	}707	public WebElement waitForElementToAppear(By locator) {708		WebDriverWait wait = new WebDriverWait(this.driver, WebDriverConstants.WAIT_TEN_SECS_IN_MILLI);709		wait.until(ExpectedConditions.elementToBeClickable(locator));710		return driver.findElement(locator);711	}712	public void waitForElementToAppear(WebElement e) {713		WebDriverWait wait = new WebDriverWait(this.driver, WebDriverConstants.WAIT_TEN_SECS_IN_MILLI);714		wait.until(ExpectedConditions.elementToBeClickable(e));715	}716	public void waitForElementToDisappear(By locator) {717		WebDriverWait wait = new WebDriverWait(this.driver, WebDriverConstants.WAIT_TWO_MIN);718		wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));719	}720	public void waitForElementToDisappear(WebElement e) {721		WebDriverWait wait = new WebDriverWait(this.driver, WebDriverConstants.WAIT_HALF_MIN);722		if (isElementPresent(e))723			wait.until(invisibilityOfElementLocated(e));724	}725	public void waitForElementToDisappear(WebElement e, int timeOut) {726		WebDriverWait wait = new WebDriverWait(this.driver, timeOut);727		if (isElementPresent(e))728			wait.until(invisibilityOfElementLocated(e));729	}730	public void waitForElementToDisappear(String xpath, int timeOut) {731		WebDriverWait wait = new WebDriverWait(this.driver, timeOut);732		WebElement e = this.driver.findElement(By.xpath(xpath));733		if (isElementPresentAndDisplayed(e))734			wait.until(invisibilityOfElementLocated(e));735	}736	public void waitForPageTransition(WebElement identifier, String attributeName, String attribValue1,737			String attribValue2, int timeOut) {738		WebDriverWait wait;739		try {740			wait = new WebDriverWait(this.driver, timeOut);741			wait.until(isElementAttributeValuePresent(identifier, attributeName, attribValue1));742		} catch (Exception ex) {743			if (ex instanceof ElementNotVisibleException || ex instanceof NoSuchElementException744					|| ex instanceof TimeoutException) {745				logger.debug(746						"Didn't see the expected page element, attribute or attribute value, so continue wait, for transition.");747			}748		} finally {749			wait = new WebDriverWait(this.driver, timeOut * 2);750			wait.until(isElementAttributeValuePresent(identifier, attributeName, attribValue2));751		}752	}753	public ExpectedCondition<Boolean> invisibilityOfElementLocated(final WebElement element) {754		return new ExpectedCondition<Boolean>() {755			public Boolean apply(WebDriver driver) {756				try {757					return !(element.isDisplayed());758				} catch (NoSuchElementException e) {759					// Returns true because the element is not present in DOM. The760					// try block checks if the element is present but is invisible.761					return true;762				} catch (StaleElementReferenceException e) {763					// Returns true because stale element reference implies that element764					// is no longer visible.765					return true;766				}767			}768		};769	}770	public String getPageName() {771		String fullClassName = getClass().getName();772		int i = fullClassName.lastIndexOf(".");773		String className = fullClassName.substring(i + 1);774		return className;775	}776	public void sleep(long millis) {777		try {778			Thread.sleep(millis);779		} catch (Exception e) {780			logger.error(e.getMessage());781		}782	}783	public void scrolltoElement(String locator) {784		try {785			WebElement element = this.driver.findElement(By.xpath(locator));786			scrolltoElement(element);787		} catch (Exception ex) {788			logger.info("exception in scroll to element: " + ExceptionUtils.getFullStackTrace(ex));789		}790	}791	public void scrolltoElement(WebElement element) {792		getJavaScriptExecutor().executeScript("arguments[0].scrollIntoView(false)", element);793		sleep(500);794	}795	public void scrollTopToElement(WebElement element) {796		getJavaScriptExecutor().executeScript("arguments[0].scrollIntoView(true)", element);797		sleep(500);798	}799	public void rightClick(By locator) {800		WebElement elementToRightClick = this.driver.findElement(locator);801		Actions clicker = new Actions(this.driver);802		clicker.contextClick(elementToRightClick).perform();803	}804	public boolean waitForAlert() {805		try {806			WebDriverWait wait = new WebDriverWait(this.driver, WebDriverConstants.WAIT_FOR_VISIBILITY_TIMEOUT_IN_SEC);807			wait.until(ExpectedConditions.alertIsPresent());808			return true;809		} catch (Exception e) {810			return false;811		}812	}813	public boolean isAlertPresent() {814		try {815			driver.switchTo().alert();816			return true;817		} catch (Exception e) {818			e.printStackTrace();819			logger.info("Error while checking if alert is present" + e.getMessage());820			return false;821		}822	}823	public Alert switchToAlert() throws Exception {824		Alert alert = driver.switchTo().alert();825		return alert;826	}827	public String getAlertText() throws Exception {828		Alert alert = driver.switchTo().alert();829		return alert.getText();830	}831	public void dismissAlertIfPresent(boolean shouldWait) {832		boolean dismissed = false;833		if (shouldWait) {834			if (waitForAlert()) {835				Alert alert = this.driver.switchTo().alert();836				alert.accept();837				dismissed = true;838			}839		} else {840			// Arbitrary wait for alert to appear841			sleep(100);842			if (isAlertPresent()) {843				try {844					driver.switchTo().alert().accept();845				} catch (Exception e) {846					e.printStackTrace();847					logger.info("Error in dismissing alert.." + e.getMessage());848				}849				dismissed = true;850			}851		}852		if (!dismissed) {853			logger.error("FAIL: dismissAlertIfPresent() - No alert to dismiss");854		}855	}856	public String getSelectedLabel(WebElement element) {857		WebElement option = new Select(element).getFirstSelectedOption();858		return option.getText();859	}860	public <SelectElement> String getSelectedValue(WebElement element) {861		return (String) (new Select(element).getFirstSelectedOption()).getText();862	}863	public <SelectElement> String getSelectedOptionValue(WebElement element) {864		return (String) (new Select(element).getFirstSelectedOption()).getAttribute("value");865	}866	public String getTitle() {867		return this.driver.getTitle();868	}869	public String getTextForElementIfPresent(By locator) {870		String text = null;871		if (isElementPresent(locator)) {872			text = this.driver.findElement(locator).getText();873		}874		return text;875	}876	public List<String> getTextListForElements(By locator) {877		List<String> textList = new ArrayList<String>();878		List<WebElement> wElmList = this.driver.findElements(locator);879		for (WebElement wlm : wElmList) {880			try {881				textList.add(wlm.getText());882			} catch (Exception e) {883				textList.add("");884			}885		}886		return textList;887	}888	public Object executeScript(String script) {889		return ((JavascriptExecutor) this.driver).executeScript(script);890	}891	public void focus(WebElement element) {892		if ("input".equals(element.getTagName())) {893			element.sendKeys("");894		} else {895			new Actions(this.driver).moveToElement(element).perform();896		}897	}898	public void waitForAJaxCompletion() {899		try {900			ExpectedCondition<Boolean> isLoadingFalse = new ExpectedCondition<Boolean>() {901				public Boolean apply(WebDriver driver) {902					String ajaxCount = (String) ((JavascriptExecutor) driver)903							.executeScript("return '' + XMLHttpRequest.prototype.ajaxCount");904					if (ajaxCount != null && ajaxCount.equals("undefined")) {905						monkeyPatch();906						return true;907					}908					if (ajaxCount != null && Double.parseDouble(ajaxCount) > 0.0d) {909						return false;910					} else {911						return true;912					}913				}914			};915			Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofMinutes(1))916					.pollingEvery(Duration.ofMillis(500)).ignoring(NoSuchElementException.class);917			wait.until(isLoadingFalse);918		} catch (Exception e) {919			logger.error(ExceptionUtils.getFullStackTrace(e));920		}921	}922	public void monkeyPatch() {923		String ajaxCount = (String) ((JavascriptExecutor) driver)924				.executeScript("return '' + XMLHttpRequest.prototype.ajaxCount");925		if (ajaxCount != null && ajaxCount.equals("undefined")) {926			getJavaScriptExecutor().executeScript(927					"!function(t){function n(){t.ajaxCount++,console.log(\"Ajax count when triggering ajax send: \"+t.ajaxCount)}function a(){t.ajaxCount>0&&t.ajaxCount--,console.log(\"Ajax count when resolving ajax send: \"+t.ajaxCount)}t.ajaxCount=0;var e=t.send;t.send=function(t){return this.addEventListener(\"readystatechange\",function(){null!=this&&this.readyState==XMLHttpRequest.DONE&&a()},!1),n(),e.apply(this,arguments)};var o=t.abort;return t.abort=function(t){return a(),o.apply(this,arguments)},t}(XMLHttpRequest.prototype);");928		}929	}930	public void uploadFile(WebElement element, String fileName) {931		element.sendKeys(fileName);932	}933	public static void setClipboardData(String string) {934		// StringSelection is a class that can be used for copy and paste operations.935		StringSelection stringSelection = new StringSelection(string);936		Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);937	}938	public void goBack() {939		this.driver.navigate().back();940	}941	public boolean isPageContainsText(String s) {942		return pageSource().contains(s);943	}944	public void assertText(String s) {945		Assert.assertTrue(pageSource().contains(s), "Expect text '" + s + "' in html source but not found.");946	}947	public void assertTextNotPresent(String s) {948		Assert.assertTrue(!(pageSource().contains(s)), "Expect text '" + s + "' in html source is found.");949	}950	public void assertTitle(String s) {951		Assert.assertEquals(s, this.driver.getTitle(),952				"Expect HTML title '" + s + "' but got '" + this.driver.getTitle() + "'.");953	}954	public long getIndexofWebElementMatchingString(List<WebElement> list, String match) {955		int index = -1;956		for (int i = 0; i < list.size(); i++) {957			if (list.get(i).getText().trim().equals(match)) {958				index = i;959				break;960			}961		}962		return index;963	}964	public void waitUntilElementHasAttribute(final WebElement e, final String attributeName) {965		WebDriverWait wait = new WebDriverWait(driver, WebDriverConstants.WAIT_FOR_VISIBILITY_TIMEOUT_IN_SEC);966		wait.until(new ExpectedCondition<Boolean>() {967			public Boolean apply(WebDriver driver) {968				return !(e.getAttribute(attributeName) == null || e.getAttribute(attributeName).isEmpty());969			}970		});971	}972	public String getAbsolutePath(String filePath) {973		String absolutePath = null;974		try {975			File file = new File(filePath);976			absolutePath = file.getAbsolutePath();977		} catch (Exception e) {978			e.printStackTrace();979		}980		return absolutePath;981	}982	public boolean hoverOnElement(WebElement element) {983		try {984			Actions builder = new Actions(this.driver);985			Actions hoverOverRegistrar = builder.moveToElement(element);986			hoverOverRegistrar.perform();987			Thread.sleep(500);988			return true;989		} catch (Exception e) {990			e.printStackTrace();991			return false;992		}993	}994	public Boolean isAttribtuePresent(WebElement element, String attribute) {995		Boolean result = false;996		try {997			String value = element.getAttribute(attribute);998			if (value != null) {999				result = true;1000			}1001		} catch (Exception e) {1002		}1003		return result;1004	}1005	public String getAttributeValue(WebElement element, String attribute) {1006		try {1007			if (isAttribtuePresent(element, attribute)) {1008				return element.getAttribute(attribute);1009			}1010		} catch (Exception e) {1011			e.printStackTrace();1012		}1013		return "";1014	}1015	public void gotoURL(String url) {1016		this.driver.get(url);1017		waitForAJaxCompletion();1018	}1019	public void gotoURLInNewWindow(String url) {1020		getJavaScriptExecutor().executeScript("window.open('" + url + "','_blank');");1021	}1022	public void elementHighlighter(WebElement element) {1023		scrolltoElement(element);1024		getJavaScriptExecutor().executeScript("arguments[0].setAttribute(\"style\", \"border: 5px solid red;\");",1025				element);1026	}1027	public void waitImplicitly() {1028		driver.manage().timeouts().implicitlyWait(WebDriverConstants.WAIT_HALF_MIN, TimeUnit.SECONDS);1029	}1030	public void waitImplicitly(int timeOutInSeconds) {1031		driver.manage().timeouts().implicitlyWait(timeOutInSeconds, TimeUnit.SECONDS);1032	}1033	public void scrollElementToUserView(WebElement elem) {1034		getJavaScriptExecutor().executeScript(1035				"window.scrollTo(" + (elem.getLocation().x - 500) + "," + (elem.getLocation().y - 500) + ");");1036	}1037	public void scrollHorizontallyTo(WebElement elem, WebElement container) {1038		getJavaScriptExecutor().executeScript("$(arguments[0],arguments[1])[0].scrollIntoView(false)", elem, container);1039	}1040	public void selectCheckbox(WebElement element) {1041		scrolltoElement(element);1042		if (!element.isSelected())1043			element.click();1044	}1045	public void unselectCheckbox(WebElement element) {1046		scrolltoElement(element);1047		if (element.isSelected())1048			element.click();1049	}1050	public boolean isLinkValid(WebElement linkElement) {1051		boolean respCode = false;1052		URL url = null;1053		HttpURLConnection connection = null;1054		try {1055			url = new URL(linkElement.getAttribute("href"));1056			connection = (HttpURLConnection) url.openConnection();1057			if (connection.getResponseCode() >= 200 && connection.getResponseCode() < 400) {1058				respCode = true;1059			}1060			return respCode;1061		} catch (Exception exp) {1062			exp.printStackTrace();1063			return respCode;1064		}1065	}1066	public boolean verifyPageTitleViaHttpClient(WebElement linkElement, String pageTitle) {1067		boolean respCode = false;1068		URL url = null;1069		String actualPageTitle = null;1070		HttpURLConnection connection = null;1071		try {1072			String urltest = linkElement.getAttribute("href");1073			url = new URL(urltest);1074			connection = (HttpURLConnection) url.openConnection();1075			if (connection.getResponseCode() >= 200 && connection.getResponseCode() < 400) {1076				InputStream inStream = connection.getInputStream();1077				Document doc = Jsoup.parse(IOUtils.toString(inStream, connection.getContentEncoding()));1078				actualPageTitle = doc.title();1079				if (actualPageTitle.equals(pageTitle)) {1080					respCode = true;1081				}1082			}1083			return respCode;1084		} catch (Exception exp) {1085			exp.printStackTrace();1086			return respCode;1087		}1088	}1089}...Source:Helper.java  
...23	void setDriver(WebDriver driverToSet);24	//=====25	// Driver-related actions26	//=====27	default JavascriptExecutor getJavascriptExecutor() {28		return (JavascriptExecutor) getDriver();29	}30	default void executeAsyncJavascript(String javascriptToExecute, Object... arguments) {31		getJavascriptExecutor().executeAsyncScript(javascriptToExecute, arguments);32	}33	default void executeAsyncJavascript(String javascriptToExecute) {34		getJavascriptExecutor().executeAsyncScript(javascriptToExecute);35	}36	default void executeJavascript(String javascriptToExecute, Object... arguments) {37		getJavascriptExecutor().executeScript(javascriptToExecute, arguments);38	}39	default void executeJavascript(String javascriptToExecute) {40		getJavascriptExecutor().executeScript(javascriptToExecute);41	}42	default void focus(String cssSelector) {43		executeJavascript("$('" + cssSelector + "').focus()");44	}45	default void focus(WebElement element) {46		executeJavascript("$(arguments[0]).focus()", element);47	}48	default void scrollDown(int amountInPixels) {49		executeJavascript("window.scrollBy(0, arguments[0]);", amountInPixels);50	}51	default void scrollToBottom() {52		executeJavascript("window.scrollTo(0, document.body.scrollHeight);");53	}54	default void scrollToElement(WebElement element) {...Source:ExpectedConditionsUtils.java  
1package org.qamation.webdriver.utils;2import org.openqa.selenium.By;3import org.openqa.selenium.support.ui.ExpectedConditions;4import org.openqa.selenium.support.ui.WebDriverWait;5import org.qamation.utils.StringUtils;6import org.openqa.selenium.JavascriptExecutor;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.support.ui.ExpectedCondition;10import javax.annotation.Nullable;11import java.util.List;12import java.util.concurrent.TimeUnit;13import com.google.common.base.Function;14/**15 * Created by pavel.gouchtchine on 12/14/2016.16 */17public class ExpectedConditionsUtils {18    private final static String DOCUMENT_READY_ASYNC_SCRIPT = StringUtils.readFileIntoString("document_ready_async.js");19    private final static String GET_DOCUMENT_CONTENT_ASYNC_SCRIPT = StringUtils.readFileIntoString("get_document_content_async.js");20    private final static String MUTATIONS_OBSERVER_ASYNC_SCRIPT = StringUtils.readFileIntoString("wait_page_changes_stop.js");21    private final static String SCRIPTS_LOADING_STOPED = StringUtils.readFileIntoString("wait_scripts_loading_stops.js");22    public static ExpectedCondition<Boolean> documentReadyAsync() {23        return createAsyncJSCondition(DOCUMENT_READY_ASYNC_SCRIPT);24    }25    public static ExpectedCondition<Boolean> browserContentStoppedChangingCondition() {26        ExpectedCondition<Boolean> cond = new ExpectedCondition<Boolean>() {27            @Nullable28            @Override29            public Boolean apply(@Nullable WebDriver drvr) {30                JavascriptExecutor js = WebDriverUtils.getJavaScriptExecutor(drvr);31                String md5_1 = getPageContentMD5(js);32                long sleepIntervalMils = TimeOutsConfig.getPageChangesIntervalMillis();//getMillsecondsFromSystemProperties(PATE_MUTATIONS_INTERVAL_SYS_PROP);33                sleep(sleepIntervalMils);34                String md5_2 = getPageContentMD5(js);35                if (md5_1.equals(md5_2)) return true;36                return false;37            }38        };39        return cond;40    }41    public static ExpectedCondition<Long> pageMutationsStoped(final WebElement element) {42        ExpectedCondition condition = new ExpectedCondition<Long>() {43            @Nullable44            @Override45            public Long apply(@Nullable WebDriver drvr) {46                JavascriptExecutor jse = WebDriverUtils.getJavaScriptExecutor(drvr);47                long mutationsTimeOut = TimeOutsConfig.getPageChangesTimeOutMillis(); //getMillsecondsFromSystemProperties(PAGE_MUTATIONS_TIME_OUT_SYS_PROP);48                long mutationsInterval = TimeOutsConfig.getPageChangesIntervalMillis();// getMillsecondsFromSystemProperties(PATE_MUTATIONS_INTERVAL_SYS_PROP);49                Long result = (Long)jse.executeAsyncScript(MUTATIONS_OBSERVER_ASYNC_SCRIPT,mutationsTimeOut,mutationsInterval,element);50                return result;51            }52        };53        return condition;54    }55    public static ExpectedCondition<Long> downloadScriptsStops() {56        ExpectedCondition condition = new ExpectedCondition<Long> () {57            @Nullable58            @Override59            public Long apply(@Nullable WebDriver webDriver) {60                JavascriptExecutor js = WebDriverUtils.getJavaScriptExecutor(webDriver);61                Long result = (Long) js.executeAsyncScript(SCRIPTS_LOADING_STOPED,TimeOutsConfig.getLoadScriptTimeOutMillis(), TimeOutsConfig.getLoadScriptIntervalMillis());62                return result;63            }64        };65        return condition;66    }67    public static Function<WebDriver,Boolean> getDocumentReadyCondition() {68        Function<WebDriver,Boolean> condition = new Function<WebDriver, Boolean>() {69            @Override70            public Boolean apply(WebDriver drvr) {71                JavascriptExecutor jse = WebDriverUtils.getJavaScriptExecutor(drvr);72                Boolean result = (Boolean)jse.executeAsyncScript(DOCUMENT_READY_ASYNC_SCRIPT);73                return result;74            }75        };76        return condition;77    }78    /*79    public static ExpectedCondition<Boolean> getSpinnerDissapearedCondition(final By spinnerLocation) {80        ExpectedCondition<Boolean> spinnerDisappers = new ExpectedCondition<Boolean>(){81            public Boolean apply(final WebDriver drvr) {82                List<WebElement> spinners = drvr.findElements(spinnerLocation);83                if (spinners.isEmpty()) {84                    return Boolean.valueOf(true);85                }86                return Boolean.valueOf(false);87            }88        };89        return spinnerDisappers;90    }91*/92    public static Function<WebDriver,Boolean> getSpinnerDissapearedCondition(final By spinnerLocation) {93        Function<WebDriver, Boolean> f = new Function<WebDriver, Boolean>() {94            @Override95            public Boolean apply(final WebDriver drvr) {96                List<WebElement> spinners = drvr.findElements(spinnerLocation);97                if (spinners.isEmpty()) {98                    return Boolean.valueOf(true);99                }100                return Boolean.valueOf(false);101            }102        };103        return f;104    }105    private static String getPageContentMD5 (JavascriptExecutor js) {106        String content = (String)js.executeAsyncScript(GET_DOCUMENT_CONTENT_ASYNC_SCRIPT);107        String md5 = StringUtils.getMD5(content);108        return md5;109    }110    private static ExpectedCondition<Boolean> createAsyncJSCondition(final String script) {111        ExpectedCondition<Boolean> condition = new ExpectedCondition<Boolean>() {112            @Nullable113            @Override114            public Boolean apply(@Nullable WebDriver drvr) {115                JavascriptExecutor jse = WebDriverUtils.getJavaScriptExecutor(drvr);116                Boolean result = (Boolean)jse.executeAsyncScript(script);117                return result;118            }119        };120        return condition;121    }122    private static ExpectedCondition<Boolean> createSyncJSCondition(final String script) {123        ExpectedCondition<Boolean> condition = new ExpectedCondition<Boolean>() {124            @Nullable125            @Override126            public Boolean apply(@Nullable WebDriver drvr) {127                JavascriptExecutor jse = WebDriverUtils.getJavaScriptExecutor(drvr);128                Boolean result = (Boolean)jse.executeScript(script);129                return result;130            }131        };132        return condition;133    }134    private static void sleep(long mills) {135        try {136            Thread.sleep(mills);137        } catch (InterruptedException e) {138            throw new RuntimeException("Unable to sleep.", e);139        }140    }141}142    /*143    public static ExpectedCondition<Boolean> createAjaxStoppedAsyncCondition(final WebDriver drvr, ) {144        System.out.print("AJAX stopped: ");145        return createAsyncJSCondition(drvr, AJAX_STOPPED_ASYNC_SCRIPT, scriptTimeOut, timeUnits);146    }147    public ExpectedCondition<Boolean> createJQueryStoppedAsyncCondition(final WebDriver drvr) {148        System.out.print("JQuery Stopped: ");149        return createAsyncCondition(drvr, JQUERY_STOPPED_ASYNC_SCRIPT, 120, TimeUnit.SECONDS);150    }151    public ExpectedCondition<Boolean> createJQueryDefinedAsyncCondition(final WebDriver drvr) {152        System.out.print("JQuery Defined: ");153        return createAsyncCondition(drvr, JQUERY_DEFINED_ASYNC_SCRIPT, 120, TimeUnit.SECONDS);154    }155    public ExpectedCondition<Boolean> createDocumentReadySyncCondition(final WebDriver drvr) {156        System.out.print("Document ready: ");157        return createSyncCondition(drvr, DOCUMENT_READY_SYNC_SCRIPT);158    }159    public ExpectedCondition<Boolean> createJQueryStoppedSyncCondition(final WebDriver drvr) {160        System.out.print("JQuery Stopped: ");161        return createSyncCondition(drvr, JQUERY_STOPPED_SYNC_SCRIPT);162    }163    public ExpectedCondition<Boolean> createJQueryDefinedSyncCondition(final WebDriver drvr) {164        System.out.print("JQuery Defined: ");165        return createSyncCondition(drvr, JQUERY_DEFINED_SYNC_SCRIPT);166    }167   */...Source:WebDriverHelper.java  
...75        System.setProperty("webdriver.chrome.driver", getDriverLocation()  +"\\chromedriver.exe");76        return options;77    }78    //region helper methods79    public static JavascriptExecutor getJavascriptExecutor(WebDriver driver){80        return((JavascriptExecutor) driver);81    }82    public static void scrollDown(WebDriver driver){83        getJavascriptExecutor(driver).executeScript("window.scrollTo(window.pageXOffset, window.pageYOffset + 500);");84    }85    public static void scrollUp(WebDriver driver){86        getJavascriptExecutor(driver).executeScript("window.scrollTo(window.pageXOffset, window.pageYOffset - 500);");87    }88    public static RemoteWebDriver getRemoteWebDriver(WebDriver driver){89        return((RemoteWebDriver) driver);90    }91    public static Capabilities getCapabilities(WebDriver driver){92        return getRemoteWebDriver(driver).getCapabilities();93    }94    95    public static void close(WebDriver driver){96        if(driver != null){97            if(getRemoteWebDriver(driver).getSessionId() != null){98                driver.close();99                driver.quit();100            }...Source:WebUtil.java  
1package com.incubyte.gmail.utility;2import java.util.concurrent.TimeUnit;3import org.openqa.selenium.By;4import org.openqa.selenium.JavascriptExecutor;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.firefox.FirefoxDriver;9import org.openqa.selenium.ie.InternetExplorerDriver;10import org.openqa.selenium.interactions.Actions;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.WebDriverWait;13import org.slf4j.Logger;14import org.slf4j.LoggerFactory;15import org.testng.Assert;16import org.testng.Reporter;17import com.incubyte.gmail.configure.Config;18import io.github.bonigarcia.wdm.WebDriverManager;19public class WebUtil {20	public static WebDriver driver;21	private static Logger logger = LoggerFactory.getLogger(WebUtil.class);22	@SuppressWarnings("deprecation")23	public static WebDriver openBrowser() {24		WebDriverManager.chromedriver().setup();25	26		driver = new ChromeDriver();	27		driver.manage().window().maximize();28		driver.manage().deleteAllCookies();29		driver.manage().timeouts().implicitlyWait(Config.getDefaultWait(), TimeUnit.SECONDS);30		return driver;31	}32	public static void openUrl(String url) {33		driver.get(url);34		logger.info("Navigate to Url :" + url);35	}36	public static WebElement findElement(By locator, int... timeOutSeconds) {37		WebElement element = null;38		int timeOut = (timeOutSeconds.length == 0) ? Config.getDefaultWait() : timeOutSeconds[0];39		WebDriverWait wait = new WebDriverWait(driver, timeOut);40		element = wait.until(ExpectedConditions.presenceOfElementLocated(locator));41		logger.info("Located element using locator:" + locator);42		return element;43	}44	/**45	 * get javaScript Executor46	 * 47	 * @param NA48	 */49	public static JavascriptExecutor getJavaScriptExecutor() {50		JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;51		return javascriptExecutor;52	}53	/**54	 * Scroll element into view.55	 * 56	 * @param element57	 */58	public static void scrollIntoView(WebElement element) {59		try {60			getJavaScriptExecutor().executeScript("arguments[0].scrollIntoView(true);", element);61			Reporter.log("Scroll into element" + element + " view ");62		} catch (Exception e) {63			Assert.fail("Element " + element + " not found.");64		}65	}66	public static void click(WebElement element, int... timeOutSeconds) {67		int timeOut = (timeOutSeconds.length == 0) ? Config.getDefaultWait() : timeOutSeconds[0];68		WebDriverWait wait = new WebDriverWait(driver, timeOut);69		wait.until(ExpectedConditions.visibilityOf(element));70		wait.until(ExpectedConditions.elementToBeClickable(element));71		element.click();72	}73	/**74	 * Forces click on an element that is otherwise invisible to WebDriver due75	 * to hidden attribute or other issue.76	 * 77	 * @param element78	 */79	public static void jsClick(WebElement element) {80		try {81			getJavaScriptExecutor().executeScript("arguments[0].click();", element);82		} catch (Exception e) {83			Assert.fail("Element " + element + " not found.");84		}85	}86	public static Actions getActions() {87		return new Actions(driver);88	}89	/**90	 * action click on an element that is otherwise invisible to WebDriver due91	 * to hidden attribute or other issue.92	 * 93	 * @param element94	 */95	public static void actionClick(WebElement element) {96		try {97			getActions().click(element).perform();98		} catch (Exception e) {99			Assert.fail("Element " + element + " not found.");100		}101	}102	/**103	 * Try multiple ways of clicking into an element104	 * 105	 * @param webElement106	 */107	public static void superClick(WebElement webElement) {108		try {109			scrollIntoView(webElement);110			webElement.click();111		} catch (Exception e) {112			scrollIntoView(webElement);113			jsClick(webElement);114		}115	}116	public static void sendKeys(WebElement element, String value, int... timeOutSeconds) {117		int timeOut = (timeOutSeconds.length == 0) ? Config.getDefaultWait() : timeOutSeconds[0];118		if (WaitUtil.isElementVisible(element, timeOut)) {119			element.clear();120			element.sendKeys(value);121			logger.info("Entering value:" + value + " in field located by webelement:" + element);122		} else123			logger.error("Element:" + element + " not visible.");124	}125}...Source:JavaScriptUtil.java  
...6import java.util.Collections;7import java.util.List;8@Slf4j9public class JavaScriptUtil extends Base {10  private JavascriptExecutor getJavascriptExecutor() {11    return ((JavascriptExecutor) driver);12  }13  private void executeUsingJavaScript(String executionScript, WebElement element) {14    getJavascriptExecutor().executeScript(executionScript, element);15  }16  public void flash(WebElement element) {17    flash(Collections.singletonList(element));18  }19  public void flash(List<WebElement> elements) {20    for (WebElement element : elements) {21      changeColor("rgb(0,200,0)", element); // 122      changeColor(element.getCssValue("backgroundColor"), element); // 223    }24  }25  private void changeColor(String color, WebElement element) {26    executeUsingJavaScript("arguments[0].style.backgroundColor = '" + color + "'", element);27    try {28      Thread.sleep(20);29    } catch (InterruptedException e) {30      log.error(e.getMessage());31      Thread.currentThread().interrupt();32    }33  }34  public void drawBorder(WebElement element) {35    executeUsingJavaScript("arguments[0].style.border='3px solid red'", element);36  }37  public void generateAlert(String message) {38    getJavascriptExecutor().executeScript("alert('" + message + "')");39  }40  public void clickElementByJS(WebElement element) {41    executeUsingJavaScript("arguments[0].click();", element);42  }43  public void refreshBrowserByJS() {44    getJavascriptExecutor().executeScript("history.go(0)");45  }46  public String getTitleByJS() {47    return getJavascriptExecutor().executeScript("return document.title;").toString();48  }49  public String getPageInnerText() {50    return getJavascriptExecutor().executeScript("return document.documentElement.innerText;").toString();51  }52  public void scrollPageDown() {53    getJavascriptExecutor().executeScript("window.scrollTo(0,document.body.scrollHeight)");54  }55  public void scrollIntoView(WebElement element) {56    executeUsingJavaScript("arguments[0].scrollIntoView(true);", element);57  }58  public String getBrowserInfo() {59    return getJavascriptExecutor().executeScript("return navigator.userAgent;").toString();60  }61  public void sendKeysUsingJSWithId(String id, String value) {62    getJavascriptExecutor().executeScript("document.getElementById('" + id + "').value='" + value + "'");63  }64  public void sendKeysUsingJSWithName(String name, String value) {65    getJavascriptExecutor().executeScript("document.getElementByName('" + name + "').value='" + value + "'");66  }67  public void checkPageIsReady() {68    //given if condition will check ready state of page.69    if (getJavascriptExecutor().executeScript("return document.readyState").toString().equals("complete")) {70      log.debug("page Is loaded.");71      return;72    }73    for (int i = 0; i < 15; i++) {74      sleep(1000);75      // check page ready state.76      if (getJavascriptExecutor().executeScript("return document.readyState").toString().equals("complete")) {77        log.debug("page Is loaded.");78        break;79      }80    }81  }82  private void sleep(int time) {83    try {84      Thread.sleep(time);85    } catch (InterruptedException interruptedException) {86      log.error(interruptedException.getMessage());87      Thread.currentThread().interrupt();88    }89  }90}...Source:ByJavaScript.java  
...31		Preconditions.checkNotNull(script, "Cannot find elements with a null JavaScript expression.");32		this.script = script;33	}34	public List<WebElement> findElements(SearchContext context) {35		JavascriptExecutor excutor = getJavascriptExecutor(context);36		Object response = excutor.executeScript(script);37		List<WebElement> elements = getElementList(response);38		if (context instanceof WebElement) {39			filterByAncestor(elements, (WebElement) context);40		}41		return elements;42	}43	44	public WebElement findElement(SearchContext context) {45		List<WebElement> elements = findElements(context);46		if (elements.isEmpty()) {47			throw new NullPointerException("Cannot find any element");48		}49		return elements.get(0);50	}51	private static JavascriptExecutor getJavascriptExecutor(SearchContext context) {52		if (context instanceof JavascriptExecutor) {53			return (JavascriptExecutor) context;54		}55		if (context instanceof WrapsDriver) {56			WebDriver driver = ((WrapsDriver) context).getWrappedDriver();57			Preconditions.checkState(driver instanceof JavascriptExecutor, "This WebDriver doesn't support JavaScript.");58			return (JavascriptExecutor) driver;59		}60		throw new IllegalStateException("We can't invoke JavaScript from this context.");61	}62	@SuppressWarnings("unchecked")63	private static List<WebElement> getElementList(Object response) {64		if (response == null) {65			return Lists.newArrayList();...Source:ByJQuery.java  
...23        this.selector = selector;24    }25    @Override26    public WebElement findElement(SearchContext context) {27        return (WebElement) getJavascriptExecutor(context).executeScript(28                "return " + selector + ".get(0)");29    }30    /*31     * @see org.openqa.selenium.By#findElements(org.openqa.selenium.SearchContext)32     */33    @SuppressWarnings("unchecked")34    @Override35    public List<WebElement> findElements(SearchContext context) {36        return (List<WebElement>) getJavascriptExecutor(context).executeScript(37                "return " + selector + ".get()");38    }39    private JavascriptExecutor getJavascriptExecutor(SearchContext context) {40        if (context instanceof JavascriptExecutor) {41            JavascriptExecutor js = (JavascriptExecutor) context;42            injectJQuery(js);43            return js;44        }45        throw new IllegalArgumentException("context is not instance of JavascriptExecutor");46    }47    private void injectJQuery(JavascriptExecutor js) {48        Boolean noJQ = (Boolean) js.executeScript("return typeof jQuery == 'undefined'");49        if (noJQ) {50            js.executeScript("var jq = document.createElement('script');"51                    + "jq.type = 'text/javascript';"52                    + "jq.src = '//code.jquery.com/jquery-2.1.0.min.js';"53                    + "document.getElementsByTagName('head')[0].appendChild(jq);");...getJavascriptExecutor
Using AI Code Generation
1import org.openqa.selenium.By;2import org.openqa.selenium.JavascriptExecutor;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.support.ui.ExpectedConditions;6import org.openqa.selenium.support.ui.WebDriverWait;7public class GetJavascriptExecutor {8public static void main(String[] args) {9System.setProperty("webdriver.chrome.driver", "C:\\\\Users\\\\Admin\\\\Downloads\\\\chromedriver_win32\\\\chromedriver.exe");10WebDriver driver = new ChromeDriver();11driver.manage().window().maximize();12WebDriverWait wait = new WebDriverWait(driver, 10);13JavascriptExecutor js = (JavascriptExecutor) driver;14js.executeScript("document.getElementsByName('q')[0].value='Selenium'");15}16}17import org.openqa.selenium.By;18import org.openqa.selenium.JavascriptExecutor;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.WebElement;21import org.openqa.selenium.chrome.ChromeDriver;22import org.openqa.selenium.support.ui.ExpectedConditions;23import org.openqa.selenium.support.ui.WebDriverWait;24public class GetJavascriptExecutor {25public static void main(String[] args) {26System.setProperty("webdriver.chrome.driver", "C:\\\\Users\\\\Admin\\\\Downloads\\\\chromedriver_win32\\\\chromedriver.exe");27WebDriver driver = new ChromeDriver();28driver.manage().window().maximize();29WebDriverWait wait = new WebDriverWait(driver, 10);30JavascriptExecutor js = (JavascriptExecutor) driver;31js.executeScript("arguments[0].value='Selenium'", searchBox);32}33}34import org.openqa.selenium.By;35import org.openqa.selenium.JavascriptExecutor;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.chrome.ChromeDriver;38import org.openqa.selenium.support.ui.ExpectedConditions;39import org.openqa.selenium.support.ui.WebDriverWait;40public class GetJavascriptExecutor {41public static void main(String[] args) {42System.setProperty("webdriver.chrome.driver", "C:\\\\Users\\\\Admin\\\\Downloads\\\\chromedriver_win32\\\\chromedriver.exe");43WebDriver driver = new ChromeDriver();getJavascriptExecutor
Using AI Code Generation
1import org.openqa.selenium.By;2import org.openqa.selenium.JavascriptExecutor;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5public class GetJavaScriptExecutor {6public static void main(String[] args) {7    WebDriver driver = new FirefoxDriver();8    JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;9    javascriptExecutor.executeScript("document.getElementsByName('q')[0].value='Selenium'");10    driver.findElement(By.name("btnG")).click();11    driver.close();12}13}14import org.openqa.selenium.By;15import org.openqa.selenium.JavascriptExecutor;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.firefox.FirefoxDriver;18public class GetJavaScriptExecutor {19public static void main(String[] args) {20    WebDriver driver = new FirefoxDriver();21    JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;22    javascriptExecutor.executeScript("document.getElementsByName('q')[0].value='Selenium'");23    driver.findElement(By.name("btnG")).click();24    driver.close();25}26}27Related Posts: How to use getAttribute() method in Selenium WebDriver?28How to use getTagName() method in Selenium WebDriver?29How to use getText() method in Selenium WebDriver?30How to use getCssValue() method in Selenium WebDriver?31How to use getSize() method in Selenium WebDriver?32How to use getSelectedOption() method in Selenium WebDriver?33How to use isSelected() method in Selenium WebDriver?34How to use isEnabled() method in Selenium WebDriver?35How to use getAttribute() method in Selenium WebDriver?36How to use getTagName() method in Selenium WebDriver?37How to use getText() method in Selenium WebDriver?38How to use getCssValue() method in Selenium WebDriver?39How to use getSize() method in Selenium WebDriver?40How to use getSelectedOption() method in Selenium WebDriver?41How to use isSelected() method in Selenium WebDriver?42How to use isEnabled() method in Selenium WebDriver?43How to use getAttribute() method in Selenium WebDriver?44How to use getTagName() method in Selenium WebDriver?45How to use getText()getJavascriptExecutor
Using AI Code Generation
1package com.test;2import org.openqa.selenium.By;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6public class ByClassExample {7	public static void main(String[] args) {8		System.setProperty("webdriver.chrome.driver", "C:\\Users\\sharath\\Downloads\\chromedriver_win32\\chromedriver.exe");9		WebDriver driver = new ChromeDriver();10		JavascriptExecutor js = (JavascriptExecutor) driver;11		js.executeScript("document.getElementById('lst-ib').value='selenium';");12		driver.findElement(By.name("btnK")).click();13	}14}15package com.test;16import org.openqa.selenium.By;17import org.openqa.selenium.WebDriver;18import org.openqa.selenium.chrome.ChromeDriver;19public class ByClassExample {20	public static void main(String[] args) {21		System.setProperty("webdriver.chrome.driver", "C:\\Users\\sharath\\Downloads\\chromedriver_win32\\chromedriver.exe");22		WebDriver driver = new ChromeDriver();23		driver.findElement(By.id("lst-ib")).sendKeys("selenium");24		driver.findElement(By.name("btnK")).click();25		String value = driver.findElement(By.id("lst-ib")).getAttribute("value");26		System.out.println(value);27	}28}29package com.test;30import org.openqa.selenium.By;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.chrome.ChromeDriver;33public class ByClassExample {34	public static void main(String[] args) {35		System.setProperty("webdriver.chrome.driver", "C:\\Users\\sharath\\Downloads\\chromedriver_win32\\chromedriver.exe");36		WebDriver driver = new ChromeDriver();getJavascriptExecutor
Using AI Code Generation
1package com.automation.selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6public class Example11 {7	public static void main(String[] args) {8		System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");9		WebDriver driver=new ChromeDriver();10		driver.manage().window().maximize();11		JavascriptExecutor js=(JavascriptExecutor)driver;12		String text=(String)js.executeScript("return document.getElementById('email').value");13		System.out.println(text);14		driver.quit();15	}16}getJavascriptExecutor
Using AI Code Generation
1package com.test;2import org.openqa.selenium.By;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6public class ByClassExample {7	public static void main(String[] args) {8		System.setProperty("webdriver.chrome.driver", "C:\\Users\\sharath\\Downloads\\chromedriver_win32\\chromedriver.exe");9		WebDriver driver = new ChromeDriver();10		JavascriptExecutor js = (JavascriptExecutor) driver;11		js.executeScript("document.getElementById('lst-ib').value='selenium';");12		driver.findElement(By.name("btnK")).click();13	}14}15package com.test;16import org.openqa.selenium.By;17import org.openqa.selenium.WebDriver;18import org.openqa.selenium.chrome.ChromeDriver;19public class ByClassExample {20	public static void main(String[] args) {21		System.setProperty("webdriver.chrome.driver", "C:\\Users\\sharath\\Downloads\\chromedriver_win32\\chromedriver.exe");22		WebDriver driver = new ChromeDriver();23		driver.findElement(By.id("lst-ib")).sendKeys("selenium");24		driver.findElement(By.name("btnK")).click();25		String value = driver.findElement(By.id("lst-ib")).getAttribute("value");26		System.out.println(value);27	}28}29package com.test;30import org.openqa.selenium.By;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.chrome.ChromeDriver;33public class ByClassExample {34	public static void main(String[] args) {35		System.setProperty("webdriver.chrome.driver", "C:\\Users\\sharath\\Downloads\\chromedriver_win32\\chromedriver.exe");36		WebDriver driver = new ChromeDriver();getJavascriptExecutor
Using AI Code Generation
1package com.automation.selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6public class Example11 {7	public static void main(String[] args) {8		System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");9		WebDriver driver=new ChromeDriver();10		driver.manage().window().maximize();11		JavascriptExecutor js=(JavascriptExecutor)driver;12		String text=(String)js.executeScript("return document.getElementById('email').value");13		System.out.println(text);14		driver.quit();15	}16}getJavascriptExecutor
Using AI Code Generation
1public class ByGetJavascriptExecutor {2	public static void main(String[] args) {3		WebDriver driver = new FirefoxDriver();4		String javascript = "return document.getElementById('lst-ib').value";5		String value = (String)((JavascriptExecutor)driver).executeScript(javascript);6		System.out.println(value);7		driver.quit();8	}9}10public class WebDriverGetJavascriptExecutor {11	public static void main(String[] args) {12		WebDriver driver = new FirefoxDriver();13		String javascript = "return document.getElementById('lst-ib').value";14		String value = (String)((JavascriptExecutor)driver).executeScript(javascript);15		System.out.println(value);16		driver.quit();17	}18}19public class WebElementGetJavascriptExecutor {20	public static void main(String[] args) {21		WebDriver driver = new FirefoxDriver();22		String javascript = "return document.getElementById('lst-ib').value";23		String value = (String)((JavascriptExecutor)driver.findElement(By.id("lst-ib"))).executeScript(javascript);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.
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.
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.
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.
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.
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.
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.
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.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!
