Desired Capabilities in Selenium WebDriver
Hello friends! in this post we will be studying about Desired Capabilities. Many times during automation, we may need to work on a particular session of browser or work with a browser having some specific configurable properties set or unset. Selenium web driver provides certain browser specific properties known as Desired Capabilities.
What are the Desired Capabilities?
Desired Capabilities are a set of properties used to configure a particular instance of the browser. We have both browser-independent capabilities like browserName, version, acceptSslCerts, etc as well as browser-specific capabilities like firefox_binary for Mozilla Firefox, chromeOptions for setting Chrome specific desired capabilities.
Setting Desired Capabilities in Selenium
Code snippet to set a capability to a browser instance –
//Specifying desired capabilities for Chrome browser DesiredCapabilities acceptSSLCertificate = DesiredCapabilities.chrome(); //Setting capability to accept SSL certificates acceptSSLCertificate.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); //Binding the capabilities to a new instance of chrome browser WebDriver driver = new ChromeDriver(acceptSSLCertificate);
Some of the capabilities common to all browsers are –
Constant Field – CapabilityType.ACCEPT_SSL_CERTS
For enabling or disabling a browser session to accept the SSL certificates by default.
Constant Field – CapabilityType.SUPPORTS_APPLICATION_CACHE
For checking if the browser instance is capable of interacting with the application cache.
Constant Field – CapabilityType.SUPPORTS_FINDING_BY_CSS
For checking if the use of CSS selector for locating web elements is enabled or not.
Constant Field – CapabilityType.TAKES_SCREENSHOT
For checking if the take screenshot ability is enabled or not.
Constant Field – CapabilityType.SUPPORTS_WEB_STORAGE
For checking if the browser instance is capable of interacting with storage objects.
Constant Field – CapabilityType.SUPPORTS_ALERTS
For checking if the browser instance is capable of handling window pop-ups.
That’s all we have in this section. Please comment below to share your views or ask any questions and don’t forget to check our complete selenium tutorial here.