4 New Features - Demo
Relative locators introduced as part of Selenium 4.
| Locators | Description |
|---|---|
| toLeftOf() | Element located to the left of specified element. |
| toRightOf() | Element located to the right of the specified element. |
| above() | Element located above with respect to the specified element. |
| below() | Element located below with respect to the specified element. |
| near() | Element is at most 50 pixels far away from the specified element. The pixel value can be modified. |
Selenium 4 Built-In Screenshot Capability
Chrome/Firefox Screen Capture of WebElement
public void test_ChromeWebElementScreenshot() throws Exception
{
driver.navigate().to("https://www.google.co.in/");
WebElement logo = driver.findElement(By.xpath("//div[@id='hplogo']"));
File file = logo.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("./target/GoogleLogo.png"));
}Chrome/Firefox Visible Screen Capture
public void test_ChromeWebPageScreenshot() throws Exception
{
driver.navigate().to("https://www.google.co.in");
File file = ((ChromeDriver) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("./target/GoogleHomePage.png"));
}Firefox Full Page Screen Capture
public void test_FirefoxFullWebPageScreenshot() throws Exception
{
driver.navigate().to("https://www.selenium.dev/");
File file = ((FirefoxDriver) driver).getFullPageScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("./target/SeleniumDevFullPageCapture.png"));
}Selenium 4 Window Handler
Chrome/Firefox Open in New Window
chromeDriver.switchTo().newWindow(WindowType.WINDOW);Chrome/Firefox Open in New Tab
chromeDriver.switchTo().newWindow(WindowType.TAB);Window Minimize
chromeDriver.manage().window().minimize();Window FullScreen
chromeDriver.manage().window().fullscreen();On this page
Contributors
Created January 23, 2020
Updated May 2, 2020
