Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Type of Selenium Driver in Java

I'm working on building out a testing framework for some sites using selenium webdriver, and my goal is to have a number of drivers running the same tests concurrently (aka a firefoxdriver, an internetexplorerdriver, and a chromedriver all running at the same time with some shared resources). However, I'm having trouble with logging which driver is doing what. I'm passing the drivers through a lot of my code, but as far as I can tell a webdriver has no knowledge of what specific type of driver it is. Is there any way to ask a webdriver element what it was instantiated as?

like image 776
iamthereplicant Avatar asked May 14 '15 13:05

iamthereplicant


People also ask

How many types of Selenium WebDriver are there?

The WebDriver API gives a more simplistic and compact programming interface for the selenium. They can be categorized into five types.

How do I find my browser driver name?

Capabilities cap = ((RemoteWebDriver) driver). getCapabilities(); String browserName = cap. getBrowserName(); String browserVersion = (String)cap. getCapability("browserVersion"); String osName = Platform.


1 Answers

You can use instanceof like

  if( driver instanceof FirefoxDriver) {
    System.out.println("Firefox it is!!");
  }
  else if( driver instanceof ChromeDriver) {
    System.out.println("Chrome it is!!");
  }
  // and so on 

For more details : What is the 'instanceof' operator used for?

like image 85
Ajinkya Avatar answered Oct 16 '22 08:10

Ajinkya