Selenium 4

What is Selenium, and why is it used?

Selenium is an open-source tool for automating web browsers. It is widely used for testing web applications to ensure functionality, compatibility, and performance across various browsers. Read More

What are the new features introduced in Selenium 4?

Relative locators for finding elements. W3C WebDriver Standard compliance. Native support for Chrome DevTools Protocol (CDP). Enhanced debugging capabilities. Improved Selenium Grid with Docker support. Read More

How do you set up Selenium 4 in a project?

Install the Selenium library Python: pip install selenium Or for Java: <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.x.x</version></dependency> Download browser drivers (e.g., ChromeDriver, GeckoDriver). Read More

What is Selenium Grid, and how has it improved in Selenium 4?

Selenium Grid allows parallel execution of tests across different browsers, operating systems, and machines.Improvements in Selenium 4: Docker support for containerized environments. Graphical user interface for easier management. Built-in observability and telemetry. Read More

How do you capture browser logs using Selenium 4?

Selenium 4 integrates Chrome DevTools Protocol (CDP) for accessing browser logs.Examples: LogEntries logs = driver.manage().logs().get(LogType.BROWSER); for (LogEntry log : logs) { System.out.println(log.getMessage()); } Read More

How do you perform browser automation using CDP in Selenium 4?

Use the DevTools interface to interact with browser features like network interception. DevTools devTools = ((ChromeDriver) driver).getDevTools(); devTools.createSession(); devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty())); Read More

Questions

List of Selenium Chrome Options [ChromeOptions] – WebDriver

In Selenium, Chrome options allow you to customize the behavior of the Chrome browser when automating tests. You can set different options such as running Chrome in headless mode, setting window sizes, and configuring the Chrome driver with various preferences... Read More

Chrome command line options flags

General Flags --headlessRun Chrome in headless mode (no UI). Useful for automation, CI/CD, etc. chrome --headless --disable-extensionsDisables all Chrome extensions. chrome --disable-extensions --start-maximizedLaunch Chrome in a maximized window. chrome --start-maximized --disable-gpuDisable hardware acceleration for GPU. Useful in headless mode. chrome... Read More

Other Topics

Web Testing- Security Testing

Security measures protect Web systems from both internal and external threats. E-commerce concerns and the growing popularity of Web-based applications have made security testing increasingly relevant. Security tests determine whether a company's security policies have been properly implemented; they evaluate... Read More

API (Application Programming Interface)

An API (Application Programming Interface) is a collection of software functions and procedures, called API calls, that can be executed by other software applications. Application developers code that links to existing APIs to make use of their functionality. This link... Read More

webdriver navigate to website

  WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com"); or use driver.navigate().to("http://www.google.com"); (not recommended ) Read More

Install the JDK Software and Set JAVA_HOME on a Windows System

- Install the JDK software. Go to http://java.sun.com/javase/downloads/index.jsp. Select the appropriate JDK software and click Download. The JDK software is installed on your computer, for example, at C:\Program Files\Java\jdk1.6.0_02. You can move the JDK software to another location if desired.... Read More

Android application testing using android SDK

Android become very popular OS in mobile phones. It's very difficult to test each devices by hand, so there is a solution. Same used by developers. Download android sdk tool http://developer.android.com/sdk/index.html . I have downloaded linux bundle here. I assume... Read More

list all the check boxes from a web page selenium

List checkBoxes = driver.findElements(By.xpath("//input[@type='checkbox']")); for (WebElement checkBox: checkBoxes) { System.out.println(checkBox.getAttribute()); // to iterate over each checkbox element. } Read More

Webtesting using selenium python

Hope you guys have basic knowledge in selenium? yep..that's enough for this. I am using linux as testing environment.. the procedures will be same in windows or other platforms, but the installation process will be different for each platforms. Prerequisite... Read More

How to start jenkins on windows

- After installing jenkins - Go to jenkins installed folder and run the command in cmd - java -jar jenkins.war - and open the dashboard http://localhost:8080 Read More

Run tests on safari | safari driver using selenium webdriver

import java.io.IOException; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.safari.SafariDriver; public class SafariTest { private WebDriver driver = null; @Test public void myTest() throws IOException, InterruptedException { driver.get("http://www.google.com"); } // Get the platform details private static boolean isSupportedPlatform()... Read More

Install jenkins as a windows service

- Download jenkins windows installation package from http://mirrors.jenkins-ci.org/windows/latest - Install the package. - After installation go to Jenkins installed folder... //programfiles/jenkins - Run the command "java -jar jenkins.war" in windows command prompt. - After jenkins gets started Open the jenkins... Read More

Wait for multiple elements presents

import java.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class waitForMultipleElements { WebDriver driver = new FirefoxDriver(); public boolean isElementPresent(By by) { try { driver.findElements(by); return true; } catch (org.openqa.selenium.NoSuchElementException e) { return false; } } public void... Read More

setup remote web driver to run on another machine | selenium webdriver

In A machine run your driver code, given below. import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class RemoteDriver { private WebDriver driver = null; @Test public void myTest() throws IOException,... Read More

working on canvas svg using selenium webdriver | xpath | highchart

For below example you have to use xpath with name space. <!DOCTYPE html> <html><body> <div id="overview-layout"> <div id="overview-body"> <div class="" id="overview-tabcontent-container"> <div data-highcharts-chart="7" class="chart" id="chart_1"> <div id="highcharts-26" class="highcharts-container"> <svg height="304" width="1154" version="1.1" xmlns="http://www.w3.org/2000/svg"> <rect zIndex="1"></rect> <path zIndex="2"></path> <g transform="translate(73,0)" style="cursor:default;text-align:center;"... Read More

Check an alert is present selenium webdriver

if (isAlertPresents()) { driver.switchTo().alert().accept(); driver.switchTo().defaultContent(); } public boolean isAlertPresents() { try { driver.switchTo().alert(); return true; }// try catch (Exception e) { return false; }// catch } Read More

class name with space selenium webdriver

Use css selector for these situations. eg: <input class="class name" driver.findElement(By.cssSelector("input[class='class name']")); driver.findElement(By.cssSelector("input.class name")); etc.. Read More

selenium select listbox options using mouse send keys

WebElement selectListBoxElement = driver.findElement("xyz"); Actions action = new Actions(driver); action.moveToElement(selectListBoxElement).click().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).click(). build().perform(); or action.moveToElement(selectListBoxElement).click().sendKeys(Keys.ARROW_DOWN) .sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build() .perform(); just use keys.Enter to select any options to selection. Read More

How to switch between tabs using selenium webdriver

driver.get("http://www.w3schools.com/"); String firstWindow = driver.getWindowHandle(); System.out.println(firstWindow); driver.findElement(By.xpath("/html/body/div[3]/div[1]/a[1]")).click(); driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL, "t"); driver.get("http://www.tutorialspoint.com"); driver.findElement( By.xpath("/html/body/div[2]/header/div[2]/div/nav/ul/li[1]/a")) .click(); driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL, "1"); driver.switchTo().window(firstWindow); Thread.sleep(5000); driver.findElement(By.linkText("REFERENCES")).click(); Read More

org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html

This is due to not setting the webdriver.ie.driver correctly. Download the ie driver from selenium hq website. Parse the correct iedriver path with register node -Dwebdriver.ie.driver C:\Users\Admin\Downloads>java -jar selenium-server-standalone-2.44.0.jar -role w ebdriver -hub http://localhost:4444/grid/register -Dwebdriver.ie.driver=C:\Users \Admin\Downloads\IEDriverServer_Win32_2.44.0\IEDriverServer.exe -port 5566 And my... Read More

get text from selenium webdriver

<div class="error"> Error <br/> <input type="hidden" value="MESSAGE" name="HardCheckErrorerrorMode"/> Locn: 1341 Has 34534 <br/> </div> If you want to output only second line value then, there is no way to do with xpath. So try with split the text by line... Read More

selenium webdriver – mouse click on an input field

  <input type="button" value="Edit" class="edit-cat" name=""> -- WebElement edit = driver.findElement(By.className("edit-cat")); Actions action = new Actions(driver); action.moveToElement(edit).click().perform(); Read More

selenium webdriver set window size using dimension

java.awt.Dimension screenSize = Toolkit.getDefaultToolkit() .getScreenSize(); Dimension dimension = new Dimension(screenSize.width, screenSize.height); driver.manage().window().setSize(dimension); and if you are getting any exception like this in linux java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. 1.... Read More

Scrolling a page using executescript EventFiringWebDriver WebDriver

package com.seleniumproject; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.events.EventFiringWebDriver; public class Scroll { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); EventFiringWebDriver efD = new EventFiringWebDriver(driver); efD.get("http://localhost:8081/web/alerts.html"); efD.executeScript("scroll(0,2000)"); } } Read More

install testng plugin on eclipse

- go to help menu on eclipse - select install new software - enter url For Eclipse 3.4 and above, enter http://beust.com/eclipse. For Eclipse 3.3 and below, enter http://beust.com/eclipse1. - continue the installation. - restart eclipse done!! Read More

extract numbers from string – java

for example if you want to compare any phone number with actual value, 555-666-777 and want to avoid hyphens or what ever..and extract only numbers use replaceall with correct regular expressions. simply do replace the non digits with blank value.... Read More

verify a radio button is selected or not

  <form> <input type="radio" name="sex" value="male">Male<br> <input type="radio" name="sex" value="female">Female </form> assertTrue(driver.findElement(By.name("sex")).isSelected()) the line will verify whether the radio button is selected or not. If selected the test will pass otherwise it will return 0 and assert will fail.  ... Read More

org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

This is due to missing the chrome driver path with the node. So in machine A Run hub java -jar lib/selenium-server-standalone-2.44.0.jar -role hub In machine B register node with parameter -Dwebdriver.chrome.driver so the command should be something like this. C:\Users\Admin\Downloads>java... Read More

read a value from properties file using java

Create a property file with values userName = "test" import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class GetDataFromProperties { public static void main(String[] args) throws IOException { Properties prop = new Properties(); FileInputStream fileInput = new FileInputStream( "give the property... Read More

override an alert using javascript executor selenium web driver

[code language="javascript"] <script type="text/javascript"> function setInnerText(id, value) { document.getElementById(id).innerHTML = '<p>' + value + '</p>'; } </script> <p>This tests alerts: <a href="#" id="alert" onclick="alert('cheese');">click me</a></p> public void overrideAlert() { ((JavascriptExecutor) driver).executeScript( "window.alert = function(msg) { document.getElementById('text').innerHTML = msg; }"); driver.findElement(By.id("alert")).click();... Read More

type DefaultHttpClient is deprecated

//Update to HttpClientBuilder (import org.apache.http.impl.client.HttpClientBuilder) import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.HttpClientBuilder; public class Test { public static void main(String[] args) throws Exception { HttpClient client = HttpClientBuilder.create().build(); HttpPost post= new HttpPost(URL); HttpResponse response = client.execute(post); System.out.println(response.getStatusLine().getStatusCode()); } } Read More

Handling an alert by catching an exception selenium

driver.findElement(By.id("alert")).click(); Alert alert = wait.until(alertIsPresent()); try { //trying to send keys values to a non existing an alert box. alert.sendKeys("hello"); } catch (ElementNotVisibleException e) { System.out.println(e.getMessage()); } finally { //finally handling the alert. alert.accept(); } } Read More

Open a browser tab using selenium

driver.get(firstTabURL); driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t"); ArrayList tabs = new ArrayList (driver.getWindowHandles()); driver.switchTo().window(tabs.get(0)); driver.get(secondURL); Read More

How to enable PHPUnit in selenium IDE

In Selenium IDE for PHPunit, You need to install a PHP formatter plugin. Install this formatter plugin https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-php-formatters/ - Go to Options - On General tab Select "Enable experimental features" - Save the ide and close - Restart the IDE.... Read More

Selenium Webdriver practical, clicking on a particular footer link on ebay site.

import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class GetEbayLinks { public static WebDriver driver = null; public static void main(String[] args) { driver = new FirefoxDriver(); // going to ebay.com driver.get("http://ebay.com"); // getting the footer section... Read More

Get value from style css – selenium xpath

For example if you want to get value  Box® from a style, <span style="float: left;"Box®</span> <span style="float: left;"Ball®</span> <span style="float: left;"Bat®</span> String value =driver.findElement(By.xpath/use index or relative path).getCssValue("left"); Read More

sikuli selenium webdriver testng testing with eclipse in windows

- Download sikuli-setup.jar from http://www.sikuli.org/download.html - Copy to a folder - Double click on the jar file or run it from command prompt (make sure you have java installed 6/7), follow the instructions. - In installation window preference select 4th... Read More

Handle Java warning popup in selenium webdriver

FirefoxProfile fProfile = new FirefoxProfile(); fProfile.setAcceptUntrustedCertificates( true ); fProfile.setPreference( "security.enable_java", true ); fProfile.setPreference( "plugin.state.java", 2 ); WebDriver driver = new FirefoxDriver( fProfile ); plugin.state.java = 0 never activate, 1 = ask to activate, 2 = always activate Read More

Read PDF file using Selenium Webdriver

Download pdfbox and fontbox jars from https://pdfbox.apache.org/download.cgi To read pdf file and verify the content is present in the pdf using. import java.io.BufferedInputStream; import java.io.IOException; import java.net.URL; import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.util.PDFTextStripper; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class PdfRead... Read More

handling https certificate on firefox using selenium webdriver – this connection is untrusted issue.

import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; public class HandleFirefoxSecurity { public static WebDriver driver = null; public static void main(String[] args) { FirefoxProfile fp = new FirefoxProfile(); fp.setAcceptUntrustedCertificates(true); driver = new FirefoxDriver(fp); driver.get("untrusted website url"); } } Read More

Tools for web element locators

https://addons.mozilla.org/en-US/firefox/addon/element-locator-for-webdriv/ https://addons.mozilla.org/en-us/firefox/addon/firepath/ https://saucelabs.com/builder http://www.saucelabs.com/addons/selenium-builder-latest.xpi Read More

delete cookies using selenium webdriver

import java.util.Set; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class DeleteCookies { public static WebDriver driver = null; public static void main(String[] args) { driver = new FirefoxDriver(); driver.get("http://google.com"); Set<Cookie> co = driver.manage().getCookies(); System.out.println(co.size()); // delete all the cookies of... Read More

browser resizing using selenium

import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class TestWindowResize { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://google.co.in"); System.out.println(driver.manage().window().getSize()); Dimension dimension = new Dimension(1024, 600); driver.manage().window().setSize(dimension); System.out.println(driver.manage().window().getSize()); } } Read More

Selenium 3 geckodriver automation tests

Selenium 3 stopped support for FirefoxDriver , It will work only up to firefox version 46. To work with latest firefox browsers, you have to use Gecko Driver Download latest geckodriver from https://github.com/mozilla/geckodriver/releases Then set system property "webdriver.gecko.driver" using - System.setProperty("webdriver.gecko.driver",... Read More

How to setup grid to run firefox in selenium 3

To invoke firefox in selenium 3, you have to parse -Dwebdriver.gecko.driver=AndPathToGECKOexecutable parameter with the hub java -jar -Dwebdriver.gecko.driver=geckodriver.exe selenium-server-standalone-3.0.0-beta3.jar -role hub Make sure the parameter should be before selenium jar Read More

How to take screenshot from xvfb display centos 6 centos 7

To debug the tests in no display servers with XVFB display. Using ImageMagick - Install imagemagick - sudo yum install ImageMagick - Suppose the browser runs at display :99 using xvfb Then - In linux terminal type - export DISPLAY=:99... Read More

java.lang.NoSuchMethodError: ‘com.google.common.collect.ImmutableMap Selenium 4 webdriver chrome Maven project

To fix this, first check your project has any dependency related to "com.google.guava". like older versions resolve that dependencies. Remove the older versions And add this dependency in your pom.xml or in project build path <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>31.0.1-jre</version> </dependency> Read More