Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting up selenium Webdriver with options and capabilities

using selenium is easy though i need to start the driver with proper setup

so for now i just need that it will ignore zoom level

my code is :

public string path = AppDomain.CurrentDomain.BaseDirectory;
public IWebDriver WebDriver;
var ieD = Path.Combine(path, "bin");

DesiredCapabilities caps = DesiredCapabilities.InternetExplorer();
caps.SetCapability("ignoreZoomSetting", true);

now my current code is only passing the path of the driver as parameter

WebDriver = new InternetExplorerDriver(ieD);

how can i properly pass both capabilities and drivers path?

like image 553
Avia Afer Avatar asked Jan 14 '23 00:01

Avia Afer


1 Answers

There is a InternetExplorerOptions class for IE options, See source, which has a method AddAdditionalCapability. However, for your ignoreZoomSetting, the class has already provided a property called IgnoreZoomLevel, so you don't need to set capability.

On the other hand, InternetExplorerDriver has a constructor for both path of IEDriver and InternetExplorerOptions. Source

public InternetExplorerDriver(string internetExplorerDriverServerDirectory, InternetExplorerOptions options)

Here's how you use it:

var options = new InternetExplorerOptions {
    EnableNativeEvents = true, // just as an example, you don't need this
    IgnoreZoomLevel = true
};

// alternative
// var options = new InternetExplorerOptions();
// options.IgnoreZoomLevel = true;


// alternatively, you can add it manually, make name and value are correct
options.AddAdditionalCapability("some other capability", true);

WebDriver = new InternetExplorerDriver(ieD, options);
like image 61
Yi Zeng Avatar answered Jan 26 '23 16:01

Yi Zeng