Steps to find the Duplicate Element in an Array: Example: package TestAutomationCentral;public class FindDuplicateElement { public static void main(String[] args) { //TestAutomationCentral.com int[] arr = {1,2,3,4,5,1,2}; for(int i=0;i<arr.length-1;i++){ for(int j=i+1;j<arr.length;j++){ if(arr[i] == arr[j]){ System.out.println(“Duplicate Element: ” + arr[i]); } } } }}
This tutorial will briefly discuss the difference between getWindowHandle() and getWindowHandles() with a sample project. getWindowHandle() returns the window handle of the current or active window. getWindowHandles() returns a set of window handles for all the windows opened by the WebDriver instance. Example: package TestAutomationCentral; import org.openqa.selenium.WebDriver;import org.openqa.selenium.WindowType;import org.openqa.selenium.chrome.ChromeDriver; import java.util.Set; public class SeleniumWindowHandles { public static void main(String[] args) […]
Can WebDriver be declared as static? Yes, the declaration of a static WebDriver is valid. Why is it not recommended to declare WebDriver as static? When WebDriver is declared as static, its instance will be shared. This can result in unexpected errors when the tests are executed in parallel, as the WebDriver instance is intended for use in a single […]
Learn the difference between findElement() and findElements() in Selenium WebDriver using Java. These methods are commonly asked in Selenium interviews. Example: package TestAutomationCentral;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import java.time.Duration;import java.util.List;public class WebElementDemo { public static void main(String[] args) { //TestAutomationCentral.com System.setProperty(“webdriver.chrome.driver”, “C:\\temp\\drivers\\chromedriver.exe”); WebDriver driver = new ChromeDriver(); driver.manage().timeouts() .implicitlyWait(Duration.ofSeconds(10)); driver.get(“https://www.google.com/”); WebElement element = driver.findElement(By.name(“q”)); element.sendKeys(“TestAutomationCentral.com”); element.submit(); List<WebElement> elements = driver.findElements(By.partialLinkText(“Test Automation […]
In this tutorial, we will discuss a detailed step-by-step guide for swapping two numbers without using a third variable in Java. This is a commonly asked question in Java interviews and Automation Testing. Through this Java program, interviewers aim to evaluate your logical skills and knowledge of Java programming. Example: package TestAutomationCentral; public class SwapNumber { public static void main(String[] […]
In this tutorial, we will discuss on Difference between the close() and quit() methods in Selenium WebDriver ‘close()’ method closes the currently active/focus window or tab of the current browser instance. ‘quit()’ method closes all open windows or tabs of the current browser instance. Example: package TestAutomationCentral;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WindowType;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.chrome.ChromeOptions;public class CloseAndQuitDemo { public static void main(String[] args) throws […]
Testing in Chrome’s Incognito mode in Selenium WebDriver. Below is the detailed tutorial and step-by-step guide to run the test execution in Chrome’s Incognito mode using Selenium with Java. Incognito mode allows users to browse the web without saving any browsing history and cookies In Incognito/Private mode, the browser creates a separate session that is isolated from the main browser […]
In this tutorial, we will discuss Running Selenium Tests in Headless Mode. Selenium WebDriver supports headless mode with different browsers like Chrome, Firefox, and Edge. Safari WebDriver does not support headless mode. What is the Headless mode in Selenium WebDriver? In headless mode, we can run Tests Without a GUI Why Headless mode and what are its advantages? Headless mode […]
This tutorial will guide you through the process of handling SSL Certificates in Selenium WebDriver for different browsers like Chrome, Firefox, Edge, and Safari in a step-by-step manner. List of SSL Certificates which we need to handle: Steps: Example package TestAutomationCentral;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.chrome.ChromeOptions;public class SSLCertificate { public static void main(String[] args) { //TestAutomationCentral.com System.setProperty(“webdriver.chrome.driver”, “C:\\temp\\drivers\\chromedriver.exe”); ChromeOptions options = new […]
STEP 1: Initial min and max values and set them to 0int min = 0, max = 0; STEP 2: Use for loop to iterate each element in the array for (int i = 0; i < arr.length; i++) STEP 3: Within the loop, write if and else if conditions to compare the current element values and set min/max with […]