Best Selenium code snippet using org.openqa.selenium.By.getWebDriver
Source:DriverPage.java  
...28	public void Log(String logMsg){29		System.out.println(logMsg);30	}31	32	public WebDriver getWebDriver() 33	{34		return driver;35	}3637	//Handle locator type38	public By ByLocator(String locator) 39	{40		By result = null;4142		if (locator.startsWith("//")) 43		{ result = By.xpath(locator); }44		else if (locator.startsWith("css=")) 45		{ result = By.cssSelector(locator.replace("css=", "")); } 46		else if (locator.startsWith("name=")) 47		{ result = By.name(locator.replace("name=", ""));48		} else if (locator.startsWith("link=")) 49		{ result = By.linkText(locator.replace("link=", "")); } 50		else 51		{ result = By.id(locator); }52		return result;53	}5455	//Assert element present56	public Boolean isElementPresent(String locator) 57	{58		Boolean result = false;59		try 60		{61			62			getWebDriver().findElement(ByLocator(locator));63			result = true;64		} 65		catch (Exception ex) { }66		return result;67	}6869    public void dragAndDrop(String loc_SourceElement, String loc_TargetElement)70    {71     Actions act = new Actions(getWebDriver());72     WebElement SourceElement = getWebDriver().findElement(ByLocator(loc_SourceElement)); 73     WebElement TargetElement = getWebDriver().findElement(ByLocator(loc_TargetElement));74     act.clickAndHold(SourceElement).moveToElement(TargetElement).pause(2000).release(TargetElement).build().perform();75    }7677	public void moveToElement(String loc)78	{79		Actions act = new Actions(getWebDriver());80		act.moveToElement(getWebDriver().findElement(By.xpath(loc))).build().perform();81	}8283	public void WaitForElementPresent(String locator, int timeout) {8485		for (int i = 0; i < timeout; i++) {86			if (isElementPresent(locator)) {87				break;88			}8990			try {91				Thread.sleep(1000);92			} catch (InterruptedException e) {93				e.printStackTrace();94			}95		}96	}9798	public void WaitForElementEnabled(String locator, int timeout) {99100		for (int i = 0; i < timeout; i++) {101			if (isElementPresent(locator)) {102				if (getWebDriver().findElement(ByLocator(locator)).isEnabled()) {103					break;104				}105			}106107			try {108				Thread.sleep(1000);109			} catch (InterruptedException e) {110				e.printStackTrace();111			}112		}113	}114115	public void WaitForElementNotEnabled(String locator, int timeout) {116117		for (int i = 0; i < timeout; i++) {118			if (isElementPresent(locator)) {119				if (!getWebDriver().findElement(ByLocator(locator)).isEnabled()) {120					break;121				}122			}123124			try {125				Thread.sleep(1000);126			} catch (InterruptedException e) {127				e.printStackTrace();128			}129		}130	}131	132	public void WaitForElementVisible(String locator, int timeout) {133134		for (int i = 0; i < timeout; i++) {135			if (isElementPresent(locator)) {136				if (getWebDriver().findElement(ByLocator(locator)).isDisplayed()) {137					break;138				}139			}140141			try {142				Thread.sleep(1000);143			} catch (InterruptedException e) {144				e.printStackTrace();145			}146		}147	}148149	public void WaitForElementNotVisible(String locator, int timeout) {150151		for (int i = 0; i < timeout; i++) {152			if (isElementPresent(locator)) {153				if (!getWebDriver().findElement(ByLocator(locator)).isDisplayed()) {154					break;155				}156			}157158			try {159				Thread.sleep(1000);160			} catch (InterruptedException e) {161				e.printStackTrace();162			}163		}164	}165	166	public void mouseOver(String locator){		167		this.WaitForElementPresent(locator, 20);		168		// find Assignments menu169		WebElement el = getWebDriver().findElement(ByLocator(locator));170		171		//build and perform the mouseOver with Advanced User Interactions API172		Actions builder = new Actions(getWebDriver());    173		builder.moveToElement(el).build().perform();174	}175	  public void dragAndDrop(String loc_SourceElement, String loc_TargetElement, String DashbaordTab)176	    {177	     Actions act = new Actions(getWebDriver());178	     WebElement SourceElement = getWebDriver().findElement(ByLocator(loc_SourceElement)); 179	     WebElement TargetElement = getWebDriver().findElement(ByLocator(loc_TargetElement));180	     WebElement SupportElement = getWebDriver().findElement(ByLocator(DashbaordTab));181	     act.clickAndHold(SourceElement).moveToElement(SupportElement).pause(2000).moveToElement(TargetElement).pause(2000).release(TargetElement).build().perform();182	    }183	public void clickOn(String locator)184	{185		moveToElement(locator);186		this.WaitForElementPresent(locator, 20);187		Assert.assertTrue(isElementPresent(locator));188		WebElement el = getWebDriver().findElement(ByLocator(locator));			189		el.click();190	}191	192	public void doubleClick(String locator)193	{		194		this.WaitForElementPresent(locator, 20);195		Assert.assertTrue(isElementPresent(locator));196		WebElement el = getWebDriver().findElement(ByLocator(locator));	197		Actions action = new Actions(driver);198		action.doubleClick(el).perform();199	}200	public void rightClick(String locator)201	{		202	203		WebElement el = getWebDriver().findElement(ByLocator(locator));	204		Actions action = new Actions(driver);205		action.contextClick(el).build().perform();206	}207	public void sendKeys(String locator, String value){208		209		this.WaitForElementPresent(locator, 20);210		Assert.assertTrue(isElementPresent(locator));211		WebElement el = getWebDriver().findElement(ByLocator(locator));212//		el.clear();213		el.sendKeys(value);214	}215	216	public void sendKeysWebElement(WebElement e, String val) {217		e.clear();218		e.sendKeys(val);219	}220	221	public void selectFrame(String locator){222		223		this.WaitForElementPresent(locator, 20);224		Assert.assertTrue(isElementPresent(locator));225		getWebDriver().switchTo().frame(locator);226		227	}228229	public void selectDropDown(String locator, String targetValue){ 230		Assert.assertTrue(isElementPresent(locator));231		this.WaitForElementPresent(locator, 20);232		new Select(getWebDriver().findElement(ByLocator(locator))).selectByVisibleText(targetValue);233		234    }235	236	public void selectDropDownByValue(String locator, String value){ 237		Assert.assertTrue(isElementPresent(locator));238		this.WaitForElementPresent(locator, 20);239		new Select(getWebDriver().findElement(ByLocator(locator))).selectByValue(value);240		241    }242	243	public void selectDropDownByIndex(WebElement locator, int value){ 244		new Select(locator).selectByIndex(value);;245		246    }247	public boolean isTextPresent(String locator, String str){		248		String message = getWebDriver().findElement(ByLocator(locator)).getText();			249		if(message.contains(str)){return true;}250		else {	return false; }251	}252	253	public String getText(String locator){254		WaitForElementPresent(locator, 5);255		String text = getWebDriver().findElement(ByLocator(locator)).getText();	256		return text;257	}258	259	public void scrollIntoView(String locator){260		  261		  WebElement elem = getWebDriver().findElement(ByLocator(locator));262		  ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", new Object[] { elem });263		 }264	265	public static By byLabel(final String label)266	{267	  return new By() {268	    @Override269	    public List<WebElement> findElements(final SearchContext context)270	    {271	      final String xpath =272	         "//*[@id = //label[text() = \"" + label + "\"]/@for]";273	      return ((FindsByXPath) context).findElementsByXPath(xpath);274	    }275	 276	    @Override277	    public WebElement findElement(final SearchContext context)278	    {279	      String xpath =280	        "id(//label[text() = \"" + label + "\"]/@for)";281	      return ((FindsByXPath) context).findElementByXPath(xpath);282	    }283	 284	    @Override285	    public String toString()286	    {287	      return "ByLabel: " + label;288	    }289	  };290	}291	292	293	//generating random string294	public static String generateRandomString(int length) throws Exception {295296		StringBuffer buffer = new StringBuffer();297		String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";298299		int charactersLength = characters.length();300301		for (int i = 0; i < length; i++) {302			double index = Math.random() * charactersLength;303			buffer.append(characters.charAt((int) index));304		}305		return buffer.toString();306	}307	308	public void checkPageLoader() {309		String loc;310		try {311			for(int i=0;i<100;i++) {312				String str = getWebDriver().findElement(By.xpath("//img[@id='loading-image']/..")).getAttribute("style");313				if(str.equals("display: none;")) {314					Thread.sleep(1000);315					break;316				}317				else if(str.equals("display: block;")) {318					Thread.sleep(1000);319				}320			}321		}322		catch(Exception e) {323			System.out.println(e.getMessage());324		}325	}326	
...Source:WebInteract.java  
...44	 * @param driver45	 * @return46	 */47	private static FluentWait<WebDriver> getFluentWait() {48		return new FluentWait<WebDriver>(DriverManager.getWebDriver())49				.withTimeout(Config.PAGE_LOADWAI_TTIME, TimeUnit.SECONDS)50				.pollingEvery(Config.POLLING_TIME, TimeUnit.MILLISECONDS);51	}52	53	/**54	 * Method to move to element55	 * @param driver56	 * @param webElement57	 */58	public static void moveToElement(WebElement webElement) {59		((JavascriptExecutor) DriverManager.getWebDriver()).executeScript("arguments[0].scrollIntoView();", webElement);60	}6162	/**63	 * Method to move to element64	 * @param driver65	 * @param webElement66	 */67	public static void moveToElementAndClick(WebElement webElement) {68		((JavascriptExecutor) DriverManager.getWebDriver()).executeScript("arguments[0].scrollIntoView();", webElement);69		webElement.click();70	}71	72	/**73	 * Method to click on object74	 * @param driver75	 * @param webElement76	 */77	public static void clickWhenReady(WebElement webElement) {78		try {79			((JavascriptExecutor) DriverManager.getWebDriver()).executeScript("arguments[0].scrollIntoView();", webElement);80			getFluentWait().until(ExpectedConditions.elementToBeClickable(webElement)).click();81		} catch (Exception e) { 82			Logger.logMessage("Exception: Webelement not available to click in clickWhenReady: " + webElement);83		}84	}8586	/**87	 * Method to get no stale element and click88	 * @param driver89	 * @param webElement90	 * @return 91	 */92	public static void getNonstaleElementAndClick(WebElement webElement) {93		try {94			((JavascriptExecutor) DriverManager.getWebDriver()).executeScript("arguments[0].scrollIntoView();", webElement);95			getFluentWait().until(ExpectedConditions.elementToBeClickable(webElement)).click();9697		} catch (Exception e) {98			for (int i = 0; i <= 10; ++i) {99				try {100					getFluentWait()101					.until(ExpectedConditions.elementToBeClickable(webElement))102					.click();103							104					break;105				} catch (StaleElementReferenceException e1) {106					continue;107				}	108			}109		}110		111	} 112	113	/**114	 * WebDriver wait115	 * @param element116	 * @return 117	 */118	public static void waitForVisibility(WebElement webElement) {119	try {	120			new WebDriverWait(DriverManager.getWebDriver(), Config.PAGE_LOADWAI_TTIME)121             .until(ExpectedConditions.visibilityOf(webElement));122		} catch (Exception e) {123			Logger.logMessage("Exception: Webelement not visible in waitForVisibility: " + webElement);124		}125	}126	127	/**128	 * WebDriver wait129	 * @param element130	 * @return 131	 */132	public static void waitForNonVisibility(WebElement webElement, int timeOut) {133	try {	134			new WebDriverWait(DriverManager.getWebDriver(), timeOut)135             .until(ExpectedConditions.invisibilityOf(webElement));136		} catch (Exception e) {137			Logger.logMessage("Exception: Webelement not visible in waitForNonVisibility: " + webElement);138		}	139	}140	141	 /**142	 * WebDriver wait143	 * @param element144	 * @return 145	 */146	public static void waitForAttribute(WebElement webElement, String attribute, String value) {147	try {	148			new WebDriverWait(DriverManager.getWebDriver(), Config.MEDIUM_PAUSE)149             .until(ExpectedConditions.attributeContains(webElement, attribute, value));150		} catch (Exception e) {151			Logger.logMessage("Exception: Webelement not visible in waitForAttribute: " + webElement);152		}153	} 154    155   /**156    * Verify webelement is present157    * @return158    */159   	public static Boolean isPresent(WebElement webElement, int timeOut) {160	   	Boolean found = false;161	   	162	   	WebInteract.waitForPageLoad(DriverManager.getWebDriver());163	   164	   	try {165		   		new WebDriverWait(DriverManager.getWebDriver(), timeOut)166		   		.until(ExpectedConditions.elementToBeClickable(webElement));167		   		168			   	if (webElement.isDisplayed())169			   		found = true;170		     171	   	} catch(Exception e) {172	   		Logger.logMessage("Exception: Webelement not present in isPresent: " + webElement);173	   		found = false;174	   	}175		  176       return found;177   	}178   179    /**180     * 181     * @param url182     */183    public static void openUrl(String url) {184    	DriverManager.getWebDriver().navigate().to(url);185//    	DriverManager.getWebDriver().manage().window().maximize();186        Logger.logMessage("Open url '" + url + "'.");187    }188    189    /**190	 * Method for mouse hover with JS191	 * @param webElement192	 * @return193	 */194	public static void mouseOverByJS(WebElement webElement) {195        String mouseOverJS = "var evObj = document.createEvent('MouseEvents');evObj.initMouseEvent"196        		+ "(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"197        		+ "arguments[0].dispatchEvent(evObj);";198        ((JavascriptExecutor)DriverManager.getWebDriver()).executeScript(mouseOverJS, webElement);199    }200	201	/**202	 * Method to Mouse over the web element using the touch action class.203	 */204    public static void mouseOver(WebElement webElement) {205        new Actions(DriverManager.getWebDriver()).moveToElement(webElement).build().perform();206    }207    208    /**209     * Clicks the identified web element by javascript.210     * @return211     */212    public static void clickByJS(WebElement webElement) {213     	((JavascriptExecutor)DriverManager.getWebDriver()).executeScript("arguments[0].click();", webElement);214     }215	216    /**217     * sets value in the identified web element by javascript.218     * @return219     */220    public static void setTextByJS(WebElement webElement, String value) {221    	JavascriptExecutor js = (JavascriptExecutor)DriverManager.getWebDriver();222    	js.executeScript("arguments[0].value='"+ value +"';", webElement);223    }224    225    /**226     * sets value in the identified web element by javascript.227     * @return228     */229    public static void backtByJS() {230    	waitForPageLoad(DriverManager.getWebDriver());231    	JavascriptExecutor js = (JavascriptExecutor)DriverManager.getWebDriver(); 232    	js.executeScript("window.history.go(-1)");233    }234    235    public static void validatePageTitle(String Expected) {236    	String Title = DriverManager.getWebDriver().getTitle();237    	System.out.println(Title);238    	Assert.assertTrue(Title.contains(Expected));239    }240241   }242    243
...Source:DriverUtil.java  
...13import java.util.concurrent.TimeUnit;14import java.util.function.Function;15public class DriverUtil {16    public static WebDriver webDriver;17    public static WebDriver getWebDriver() {18        return webDriver;19    }20    public static void close() {21        getWebDriver().close();22    }23    public static void get(String s) {24        getWebDriver().get(s);25    }26    public static void getCurrentUrl() {27        getWebDriver().getCurrentUrl();28    }29    public static void getPageSource() {30        getWebDriver().getPageSource();31    }32    public static void quit() {33        getWebDriver().quit();34    }35    public static void switchTo() {36        getWebDriver().switchTo();37    }38    public static void initDriver(DriverType driverType) {39        switch (driverType) {40            case IE:41                System.setProperty("webdriver.ie.driver", "src/main/resources/IEDriverServer.exe");42                webDriver = new InternetExplorerDriver();43                break;44            case CHROME:45                System.setProperty("webdriver.chrome.driver",46                        "src/main/resources/chromedriver.exe");47                webDriver = new ChromeDriver();48                break;49            case FIRE_FOX:50                System.setProperty("webdriver.gecko.driver",51                        "src/main/resources/geckodriver.exe");52                webDriver = new FirefoxDriver();53                break;54            default:55        }56    }57    public static void maximizeWindow() {58        getWebDriver().manage().window().maximize();59    }60    public static void navigateTo(String link) {61        getWebDriver().navigate().to(link);62    }63    public static WebElement findElement(By by) {64        return getWebDriver().findElement(by);65    }66    public static List<WebElement> findElements(By by) {67        return getWebDriver().findElements(by);68    }69    public static void click(By by) {70        findElement(by).click();71    }72    public static void clear(By by) {73        findElement(by).clear();74    }75    public static Dimension getSize(By by) {76      return  findElement(by).getSize();77    }78    public static void waitMiliseconds(int time) {79        try {80            Thread.sleep(time);81        } catch (InterruptedException e) {82            e.printStackTrace();83        }84    }85    public static void waitingTime(int time) {86        waitMiliseconds(time * 1000);87    }88    public static void implicit() {89        getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);90    }91    public static void waitInvisibilityOfElementLocated(int time, By by) {92        WebDriverWait wait = new WebDriverWait(webDriver, time * 1000);93        wait.until(ExpectedConditions.invisibilityOfElementLocated(by));94    }95    public static void invisibilityOf(int time, WebElement element) {96        WebDriverWait wait = new WebDriverWait(webDriver, time);97        wait.until(ExpectedConditions.invisibilityOf(element));98    }99    public static void waitElementToBeClickable(int time, By by) {100        WebDriverWait wait = new WebDriverWait(webDriver, time * 1000);101        wait.until(ExpectedConditions.elementToBeClickable(by));102    }103    public static void waitVisibilityOfElementLocated(int time, By by) {...Source:Driver.java  
...30                driver.set(new ChromeDriver());31        }32        driver.get().manage().window().maximize();33    }34    public WebDriver getWebDriver() {35        return driver.get();36    }37    public void killDriverSession() {38        close();39        quit();40        driver = null;41    }42    @Override43    public void get(String url) {44        getWebDriver().get(url);45    }46    @Override47    public String getCurrentUrl() {48        return getWebDriver().getCurrentUrl();49    }50    @Override51    public String getTitle() {52        return getWebDriver().getTitle();53    }54    @Override55    public List<WebElement> findElements(By by) {56        return getWebDriver().findElements(by);57    }58    @Override59    public WebElement findElement(By by) {60        return getWebDriver().findElement(by);61    }62    @Override63    public String getPageSource() {64        return getWebDriver().getPageSource();65    }66    @Override67    public void close() {68        getWebDriver().close();69    }70    @Override71    public void quit() {72        getWebDriver().quit();73    }74    @Override75    public Set<String> getWindowHandles() {76        return getWebDriver().getWindowHandles();77    }78    @Override79    public String getWindowHandle() {80        return getWebDriver().getWindowHandle();81    }82    @Override83    public TargetLocator switchTo() {84        return getWebDriver().switchTo();85    }86    @Override87    public Navigation navigate() {88        return getWebDriver().navigate();89    }90    @Override91    public Options manage() {92        return getWebDriver().manage();93    }94}...Source:Utils.java  
...15	public static ArrayList<byte[]> evidences;16	public Utils(WebDriver driver) {17		webDriver = driver;18	}19	public WebDriver getWebDriver() {20		return webDriver;21	}22	public void click(By element) {23		getWebDriver().findElement(element).click();24	}25	public void insertText(By element, String text) {26		getWebDriver().findElement(element).sendKeys(text);27	}28	public void waitElement(By element, long timeOutInSeconds) {29		WebDriverWait wait = new WebDriverWait(getWebDriver(), timeOutInSeconds);30		wait.until(ExpectedConditions.visibilityOfElementLocated(element));31	}32	public String getText(By element) {33		return getWebDriver().findElement(element).getText();34	}35	public WebElement findElement(By element) {36		return getWebDriver().findElement(element);37	}38	public void takeScreenShot() {39		if (evidences == null) {40			evidences = new ArrayList<byte[]>();41		}42		byte[] scrFile = ((TakesScreenshot) getWebDriver()).getScreenshotAs(OutputType.BYTES);43		evidences.add(scrFile);44	}45	public static ArrayList<byte[]> getEvidences() {46		return evidences;47	}48	@SuppressWarnings("rawtypes")49	public void swipeDown() {50		int x = getWebDriver().manage().window().getSize().width / 2;51		int y = getWebDriver().manage().window().getSize().height * 4 / 5;52		int moveY = getWebDriver().manage().window().getSize().height / 8;53		new TouchAction((AndroidDriver) getWebDriver()).longPress(PointOption.point(x, y))54				.moveTo(PointOption.point(x, moveY)).release().perform();55	}56}...Source:AbstractPage.java  
...6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8public abstract class AbstractPage {9    abstract boolean isPageDisplayed();10    abstract WebDriver getWebDriver();11    boolean isElementDisplayed(By criteria) {12        try {13            return getWebDriver().findElement(criteria).isDisplayed();14        } catch (Exception e) {15            System.out.println("Element with criteria: " + criteria + " not displayed");16            return false;17        }18    }19    void setInputText(String text, String elementId) {20        WebElement webElement = getWebDriver().findElement(By.id(elementId));21        WebDriverWait wait = new WebDriverWait(getWebDriver(), 10);22        wait.until(ExpectedConditions.visibilityOf(webElement));23        ((JavascriptExecutor) getWebDriver()).executeScript("arguments[0].value='" + text + "';", webElement);24    }25    void click(String elementId) {26        WebElement webElement = getWebDriver().findElement(By.id(elementId));27        ((JavascriptExecutor) getWebDriver()).executeScript("arguments[0].click();", webElement);28    }29    String getInputText(String elementId) {30        WebElement webElement = getWebDriver().findElement(By.id(elementId));31        return webElement.getAttribute("value");32    }33    String getInputText(WebElement parentElement, String elementId) {34        WebElement webElement = parentElement.findElement(By.id(elementId));35        return webElement.getAttribute("value");36    }37    String getInnerText(WebElement parentElement, String innerElement) {38        WebElement webElement = parentElement.findElement(By.id(innerElement));39        return webElement.getAttribute("innerHTML");40    }41}...Source:DemoRunner.java  
...14public class DemoRunner {15    @Test16    public void weatherTest() {17//        driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);18        ThreadLocalDriver.getWebDriver().get("https://www.google.com");19        ThreadLocalDriver.getWebDriver().findElement(By.name("q")).sendKeys("погода ÐинÑк");20        ThreadLocalDriver.getWebDriver().findElement(By.name("q")).submit();21        ThreadLocalDriver.getWebDriver().findElement(By.xpath("//a[@href='https://www.gismeteo.by/weather-minsk-4248/']")).click();22        ThreadLocalDriver.getWebDriver().findElement(By.xpath("//a[@title = 'Ðогода в ÐинÑке на завÑÑа']")).click();23        WebElement firstResult = new WebDriverWait(ThreadLocalDriver.getWebDriver(), 10000)24                .until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='chart chart__temperature']/div/div[5]")));25        String temperature = ThreadLocalDriver.getWebDriver().findElement(By.xpath("//div[@class='chart chart__temperature']/div/div[5]")).getText();26        System.out.println(temperature);27        ThreadLocalDriver.getWebDriver().close();28        Driver.setWebDriver(null);29    }30}...Source:QuickView.java  
...9import org.openqa.selenium.support.ui.WebDriverWait;10public class QuickView extends BasePage{11    public QuickView(WebDriver webDriver){12        super(webDriver);13        PageFactory.initElements(getWebDriver(), this);14    }15    @FindBy(id = "add_to_cart")16    private WebElement addToCart;17    @FindBy(xpath = "/html[1]/body[1]/div[1]/div[1]/div[3]/form[1]/div[1]/div[2]/p[1]/a[2]")18    private WebElement plus;19    public void increaseNrProducts(){20        new WebDriverWait(getWebDriver(),5).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.className("fancybox-iframe")));21        new WebDriverWait(getWebDriver(), 5).until(ExpectedConditions.elementToBeClickable(plus));22        getPlus().click();23        getPlus().click();24    }25    public void setChangeSize(String value){26        Select select = new Select(getWebDriver().findElement(By.id("group_1")));27        select.selectByValue(value);28    }29    public PopUpCart clickAddCart() throws InterruptedException {30        getAddToCart().click();31        Thread.sleep(5000);32        getWebDriver().switchTo().defaultContent();33        new WebDriverWait(getWebDriver(),5).until(ExpectedConditions.visibilityOfElementLocated(By.id("layer_cart")));34        return new PopUpCart(getWebDriver());35    }36    public WebElement getPlus(){ return plus; }37    public WebElement getAddToCart(){ return addToCart; }38}...getWebDriver
Using AI Code Generation
1WebElement element = driver.findElement(by);2element.click();3By by = By.getWebDriver("css", "div#myId");4WebElement element = driver.findElement(by);5element.click();6By by = By.getWebDriver("id", "myId");7WebElement element = driver.findElement(by);8element.click();9By by = By.getWebDriver("name", "myName");10WebElement element = driver.findElement(by);11element.click();12By by = By.getWebDriver("linkText", "My Link");13WebElement element = driver.findElement(by);14element.click();15By by = By.getWebDriver("partialLinkText", "My Link");16WebElement element = driver.findElement(by);17element.click();18By by = By.getWebDriver("className", "myClassName");19WebElement element = driver.findElement(by);20element.click();21By by = By.getWebDriver("tagName", "myTagName");22WebElement element = driver.findElement(by);23element.click();24WebElement element = driver.findElement(by);25element.click();26By by = By.getWebDriver("css", "div#myId");27WebElement element = driver.findElement(by);28element.click();29By by = By.getWebDriver("id", "myId");30WebElement element = driver.findElement(by);31element.click();32By by = By.getWebDriver("name", "myName");33WebElement element = driver.findElement(by);34element.click();35By by = By.getWebDriver("linkText", "My Link");36WebElement element = driver.findElement(by);37element.click();getWebDriver
Using AI Code Generation
1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4public class ByGetWebDriver {5    public static void main(String[] args) {6        WebDriver driver = null;7        By locator = null;8        WebElement element = null;9        element = locator.getWebDriver(driver);10    }11}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!!
