How to use getBuildInformation method of org.openqa.selenium.WebDriverException class

Best Selenium code snippet using org.openqa.selenium.WebDriverException.getBuildInformation

WebDriverException org.openqa.selenium.WebDriverException

The WebDriver error - unknown error, happens when the driver tries to process a command and an unspecified error occurs.

The error can generally be isolated to the specific driver. It is a good practice to read the error message for any pointers on why the error occurred.

Example:

The error message shows that Selenium webdriver is not able to focus on element. generally, it happens due to incompatibility between Browser and Driver versions

copy
1Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element 2 (Session info: chrome=61.0.3163.100) 3 (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 4Command duration or timeout: 0 milliseconds 5Build info: version: 'unknown', revision: 'unknown', time: 'unknown' 6System info: host: 'DWA7DEVOS00170', ip: '10.96.162.167', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_25' 7Driver info: org.openqa.selenium.chrome.ChromeDriver

Solutions:

  • Upgrade browser version
  • Upgrade driver version

Code Snippets

Here are code snippets that can help you understand more how developers are using

copy

Full Screen

...41 System.err.println("Message - " + e.getMessage());42 System.err.println("Additional info - " + e.getAdditionalInformation());43 System.err.println("Support url - " + e.getSupportUrl());44 System.err.println("System info - " + e.getSystemInformation());45 System.err.println("Build info - " + e.getBuildInformation());46 throw e;47 } catch (Throwable t) {48 System.err.println("Class - " + t.getClass());49 System.err.println("Message - " + t.getMessage());50 System.err.println("--------");51 t.printStackTrace(System.err);52 System.err.println("--------");53 throw t;54 }55 return driver;56 }57 public static void takeScreenshot(WebDriver browser, String screenshotName) {58 if (browser instanceof TakesScreenshot) {59 String testCaseClass = calledByClass();...

Full Screen

Full Screen
copy

Full Screen

...35 "" : "For documentation on this error, please visit: " + getSupportUrl() + "\n";36 return String.format("%s%s%s\nSystem info: %s\nDriver info: %s",37 originalMessageString == null ? "" : originalMessageString + "\n",38 supportMessage,39 getBuildInformation(),40 getSystemInformation(),41 getDriverInformation());42 }43 public String getSystemInformation() {44 return String.format("os.name: '%s', os.arch: '%s', os.version: '%s', java.version: '%s'",45 System.getProperty("os.name"),46 System.getProperty("os.arch"),47 System.getProperty("os.version"),48 System.getProperty("java.version"));49 }50 public String getSupportUrl() {51 return null;52 }53 public BuildInfo getBuildInformation() {54 return new BuildInfo();55 }56 public String getDriverInformation() {57 String driverInformation = "driver.version: " + getDriverName(getStackTrace());58 if (sessionId != null) {59 driverInformation += "\nSession ID: " + sessionId;60 }61 return driverInformation;62 }63 public void setSessionId(String sessionId) {64 this.sessionId = sessionId;65 }66 public static String getDriverName(StackTraceElement[] stackTraceElements) {67 String driverName = "unknown";...

Full Screen

Full Screen
copy

Full Screen

...57 return new StringBuilder()58 .append((originalMessageString == null) ? ""59 : new StringBuilder().append(originalMessageString)60 .append("\n").toString()).toString();61 /​*.append(supportMessage).append(getBuildInformation())62 .append("\n").append(getSystemInformation())63 .append(getAdditionalInformation()).toString();*/​64 }65 66}...

Full Screen

Full Screen

getBuildInformation

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException;2import org.openqa.selenium.remote.RemoteWebDriver;3import java.util.Map;4import java.util.HashMap;5import java.util.Set;6import java.util.Iterator;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.openqa.selenium.remote.RemoteWebDriver;9import org.openqa.selenium.remote.RemoteWebElement;10import org.openqa.selenium.remote.Augmenter;11import org.openqa.selenium.remote.CapabilityType;12import org.openqa.selenium.remote.DesiredCapabilities;13import org.openqa.selenium.remote.DriverCommand;14import org.openqa.selenium.remote.ErrorHandler;15import org.openqa.selenium.remote.HttpCommandExecutor;16import org.openqa.selenium.remote.HttpCommandExecutor;17import org.openqa.selenium.remote.Response;18import org.openqa.selenium.remote.RemoteWebDriver;19import org.openqa.selenium.remote.RemoteWebElement;20import org.openqa.selenium.remote.Augmenter;21import org.openqa.selenium.remote.CapabilityType;22import org.openqa.selenium.remote.DesiredCapabilities;23import org.openqa.selenium.remote.DriverCommand;24import org.openqa.selenium.remote.ErrorHandler;25import org.openqa.selenium.remote.HttpCommandExecutor;26import org.openqa.selenium.remote.HttpCommandExecutor;27import org.openqa.selenium.remote.Response;28import org.openqa.selenium.remote.RemoteWebDriver;29import org.openqa.selenium.remote.RemoteWebElement;30import org.openqa.selenium.remote.Augmenter;31import org.openqa.selenium.remote.CapabilityType;32import org.openqa.selenium.remote.DesiredCapabilities;33import org.openqa.selenium.remote.DriverCommand;34import org.openqa.selenium.remote.ErrorHandler;35import org.openqa.selenium.remote.HttpCommandExecutor;36import org.openqa.selenium.remote.HttpCommandExecutor;37import org.openqa.selenium.remote.Response;38import org.openqa.selenium.remote.RemoteWebDriver;39import org.openqa.selenium.remote.RemoteWebElement;40import org.openqa.selenium.remote.Augmenter;41import org.openqa.selenium.remote.CapabilityType;42import org.openqa.selenium.remote.DesiredCapabilities;43import org.openqa.selenium.remote.DriverCommand;44import org.openqa.selenium.remote.ErrorHandler;45import org.openqa.selenium.remote.HttpCommandExecutor;46import org.openqa.selenium.remote.HttpCommandExecutor;47import org.openqa.selenium.remote.Response;48import org.openqa.selenium.remote.RemoteWebDriver;49import org.openqa.selenium.remote.RemoteWebElement;50import org.openqa.selenium.remote.Augmenter;51import org.openqa.selenium.remote.CapabilityType;52import org.openqa.selenium.remote.DesiredCapabilities;53import org.openqa.selenium.remote.DriverCommand;54import org.openqa.selenium.remote.ErrorHandler;55import org.openqa.selenium.remote.HttpCommandExecutor;56import org.openqa.selenium.remote.HttpCommandExecutor;57import org.openqa.selenium.remote.Response;58import org.openqa.selenium.remote.RemoteWebDriver;59import org.openqa.selenium.remote.RemoteWebElement;60import org.openqa.selenium.remote.Augmenter;61import org.openqa

Full Screen

Full Screen

getBuildInformation

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriverException;2public class BuildInformation {3 public static void main(String[] args) {4 WebDriverException driverException = new WebDriverException();5 System.out.println(driverException.getBuildInformation());6 }7}

Full Screen

Full Screen

getBuildInformation

Using AI Code Generation

copy

Full Screen

1package com.selenium2.easy.test.server.automation;2import java.util.Date;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebDriverException;5import org.openqa.selenium.firefox.FirefoxDriver;6public class WebDriverExceptionExample {7 public static void main(String[] args) {8 WebDriver driver = new FirefoxDriver();9 try {10 System.out.println("Page title is: " + driver.getTitle());11 System.out.println("Before exception");12 throw new WebDriverException("This is a custom exception");13 } catch (WebDriverException e) {14 System.out.println("Exception occurred");15 System.out.println("Exception message is: " + e.getMessage());16 System.out.println("Exception build information is: " + e.getBuildInformation());17 System.out.println("Exception class is: " + e.getClass());18 System.out.println("Exception stack trace is: " + e.getStackTrace());19 System.out.println("Exception cause is: " + e.getCause());20 System.out.println("Exception localized message is: " + e.getLocalizedMessage());21 System.out.println("Exception date is: " + new Date());22 }23 }24}25Exception stack trace is: [Ljava.lang.StackTraceElement;@5d7e1d7726In this example, we are throwing an exception manually using throw keyword. We are using getBuildInformation() method of WebDriverException class to get the build information of the exception. The output of the above code is as follows:27Exception stack trace is: [Ljava.lang.StackTraceElement;@5d7e1d77

Full Screen

Full Screen

StackOverFlow community discussions

Questions
Discussion

What is the differnce between page object model and page factory in selenium?

How to use Sendkeys() without finding element on web page when element is already focused and waiting for input

Running a single test in maven -> No tests were executed

Selenium: How to Disable webdriver="true" in Firefox?

assets are not loaded in functional test mode

Webdriver findElements By xpath

Find element by attribute

Can I verify that an input field is masked or shows the text?

Switch tabs using Selenium WebDriver with Java

java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' using ChromeDriver and Selenium

Page Object is a class that represents a web page and hold the functionality and members.

public class LogInPage
{
    private WebElement userName;
    private WebElement password;

    public LogInPage() {
    }

    public void locateElements() {
        userName = driver.findElement(By.id("userName"));
        password = driver.findElement(By.id("password"));
    }

    public void doLogIn() {
        userName.sendKeys("qwe");
        password.sendKeys("123");
    }
}

Page Factory is a way to initialize the web elements you want to interact with within the page object when you create an instance of it.

public class LogInPage
{
    @FindBy(id="userName")
    private WebElement userName;

    @FindBy(id="password")
    private WebElement password;

    public LogInPage() {
        PageFactory.initElements(driver, this); // initialize the members like driver.findElement()
    }

    public void doLogIn() {
        userName.sendKeys("qwe");
        password.sendKeys("123");
    }
}
https://stackoverflow.com/questions/35866113/what-is-the-differnce-between-page-object-model-and-page-factory-in-selenium

Blogs

Check out the latest blogs from LambdaTest on this topic:

Test a SignUp Page: Problems, Test Cases, and Template

Every user journey on a website starts from a signup page. Signup page is one of the simplest yet one of the most important page of the website. People do everything in their control to increase the conversions on their website by changing signup pages, modifying them, performing A/B testing to find out the best pages and what not. But the major problem that went unnoticed or is usually underrated is testing the signup page. If you try all the possible hacks but fail to test it properly you’re missing on a big thing. Because if users are facing problem while signing up they leave your website and will never come back.

Selenium Testing With Selenide Element Using IntelliJ & Maven

There are a lot of tools in the market who uses Selenium as a base and create a wrapper on top of it for more customization, better readability of code and less maintenance for eg., Watir, Protractor etc., To know more details about Watir please refer Cross Browser Automation Testing using Watir and Protractor please refer Automated Cross Browser Testing with Protractor & Selenium.

Using Selenium and Python Hypothesis for Automation Testing

This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium Python Tutorial.

8 Actionable Insights To Write Better Automation Code

As you start on with automation you may come across various approaches, techniques, framework and tools you may incorporate in your automation code. Sometimes such versatility leads to greater complexity in code than providing better flexibility or better means of resolving issues. While writing an automation code it’s important that we are able to clearly portray our objective of automation testing and how are we achieving it. Having said so it’s important to write ‘clean code’ to provide better maintainability and readability. Writing clean code is also not an easy cup of tea, you need to keep in mind a lot of best practices. The below topic highlights 8 silver lines one should acquire to write better automation code.

16 Best Practices Of CI/CD Pipeline To Speed Test Automation

Every software project involves some kind of ‘processes’ & ‘practices’ for successful execution & deployment of the project. As the size & scale of the project increases, the degree of complications also increases in an exponential manner. The leadership team should make every possible effort to develop, test, and release the software in a manner so that the release is done in an incremental manner thereby having minimal (or no) impact on the software already available with the customer.

Selenium 4 Tutorial:

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.

Chapters:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful