本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeOptions.AddArguments方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeOptions.AddArguments方法的具体用法?C# ChromeOptions.AddArguments怎么用?C# ChromeOptions.AddArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeOptions
的用法示例。
在下文中一共展示了ChromeOptions.AddArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public void Login(String loginUrl)
{
var options = new ChromeOptions();
options.AddArguments("--test-type", "--start-maximized");
options.AddArguments("--test-type", "--ignore-certificate-errors");
options.BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
driver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);
driver.Navigate().GoToUrl(loginUrl);
int timeout = 0;
while (driver.FindElements(By.ClassName("logbox")).Count == 0 && timeout < 500)
{
Thread.Sleep(1);
timeout++;
}
IWebElement element = driver.FindElement(By.ClassName("logbox"));
IWebElement ElName = element.FindElement(By.Name("username"));
ElName.Clear();
ElName.SendKeys(loginName);
IWebElement ElPassword = element.FindElement(By.Id("password"));
ElPassword.Clear();
ElPassword.SendKeys(loginPassword);
IWebElement ElLogin = element.FindElement(By.Id("IBtnLogin"));
ElLogin.Click();
}
示例2: CreateChromeGridDriver
public static IWebDriver CreateChromeGridDriver(string profileName, string hubAddress)
{
if (hubAddress == null)
{
throw new ArgumentException("remoteAddress");
}
var chromeOptions = new ChromeOptions();
if (!string.IsNullOrWhiteSpace(profileName))
{
var fileChars = Path.GetInvalidFileNameChars();
var pathChars = Path.GetInvalidFileNameChars();
var invalidChars = fileChars.Union(pathChars);
profileName = String.Join("", profileName.Where(c => !invalidChars.Contains(c)));
chromeOptions.AddArguments(String.Format("user-data-dir=c:\\ChromeProfiles\\{0}", profileName));
}
RemoteWebDriver Driver = new RemoteWebDriver(new Uri(hubAddress), chromeOptions.ToCapabilities());
Driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 1, 0));
Driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1));
Driver.Manage().Window.Maximize();
return Driver;
}
示例3: ChatGeneratorClass
//private const int volumizingCounter = 100;
public ChatGeneratorClass()
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--incognito");
options.AddArguments("--start-minimized");
driver = new ChromeDriver(options);
baseUrl = "http://pofig.livetex.ru/";
}
示例4: InitializeWebDriver
private static void InitializeWebDriver() {
switch (Configuration.BrowserType) {
case BrowserType.Firefox:
WebDriver = new FirefoxDriver();
break;
case BrowserType.InternetExplorer:
var ieOptions = new InternetExplorerOptions {
EnableNativeEvents = true,
EnablePersistentHover = true,
EnsureCleanSession = true,
UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Dismiss
};
WebDriver = new InternetExplorerDriver("./", ieOptions);
break;
case BrowserType.Chrome:
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("test-type");
WebDriver = new ChromeDriver("./", chromeOptions);
break;
default:
throw new ArgumentException("Unknown browser type is specified!");
}
WebDriver.Manage().Window.Maximize();
WebDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(Configuration.ImplicitWaitTime));
}
示例5: Host
public Host()
{
// Hack
int retryCount = 3;
while (true)
{
try
{
var options = new ChromeOptions();
options.AddArguments("test-type");
var service = ChromeDriverService.CreateDefaultService(@"..\..\Scaffolding\WebDriver");
service.HideCommandPromptWindow = false;
WebDriver = new ChromeDriver(service, options);
WebDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Page = new Page(WebDriver);
Page.GotoUrl("Home");
break;
}
catch
{
if (retryCount-- == 0)
throw;
}
}
}
示例6: switch
/// <summary>
/// Get a RemoteWebDriver
/// </summary>
/// <param name="browser">the Browser to test on</param>
/// <param name="languageCode">The language that the browser should accept.</param>
/// <returns>a IWebDriver</returns>
IWebDriver IWebDriverFactory.GetWebDriver(Browser browser, string languageCode)
{
//What browser to test on?s
IWebDriver webDriver;
switch (browser.Browserstring.ToLowerInvariant())
{
case "firefox":
var firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("intl.accept_languages", languageCode);
webDriver = new FirefoxDriver(firefoxProfile);
break;
case "chrome":
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--test-type", "--disable-hang-monitor", "--new-window", "--no-sandbox", "--lang=" + languageCode);
webDriver = new ChromeDriver(chromeOptions);
break;
case "internet explorer":
webDriver = new InternetExplorerDriver(new InternetExplorerOptions { BrowserCommandLineArguments = "singleWindow=true", IntroduceInstabilityByIgnoringProtectedModeSettings = true, EnsureCleanSession = true, EnablePersistentHover = false });
break;
case "phantomjs":
webDriver = new PhantomJSDriver(new PhantomJSOptions() {});
break;
default:
throw new NotSupportedException("Not supported browser");
}
return webDriver;
}
示例7: InitializeDriver
public virtual void InitializeDriver()
{
InitializeSettings();
switch (BrowserType)
{
case BrowserType.Chrome:
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments(new string[] { "--no-sandbox", "test-type", "--start-maximized" });
var chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = false;
Context.Driver = new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromSeconds(300.0));
break;
case BrowserType.Firefox:
var capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.UnexpectedAlertBehavior, "dismiss");
Context.Driver = new FirefoxDriver(capabilities);
break;
}
Context.Browser = new Browser();
Context.Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(Context.Settings.WaitTimeout));
Context.Driver.Navigate().GoToUrl("about:blank");
Context.Driver.SwitchTo().Window(Context.Driver.WindowHandles.First());
}
示例8: tstObject
public tstObject(int typNum)
{
brwsrType = typNum;
switch (typNum)
{
//create a Chrome object
case 1:
{
var options = new ChromeOptions();
//set the startup options to start maximzed
options.AddArguments("start-maximized");
//start Chrome maximized
driver = new ChromeDriver(@Application.StartupPath, options);
//Wait 10 seconds for an item to appear
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(4));
break;
}
//create an IE object
case 2:
{
//var options = new InternetExplorerOptions();
//set the startup options to start maximzed
//options.ToCapabilities();
driver = new InternetExplorerDriver(@Application.StartupPath);
//maximize window
driver.Manage().Window.Maximize();
//Wait 4 seconds for an item to appear
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(4));
break;
}
default:
{
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("webdriver.firefox.profile", "cbufsusm.default");
profile.AcceptUntrustedCertificates = true;
driver = new FirefoxDriver(profile); //profile
//maximize window
driver.Manage().Window.Maximize();
//Wait 4 seconds for an item to appear
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(4));
break;
}
}
}
示例9: TestConsole
static TestConsole()
{
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--disable-web-security");
chromeOptions.AddArguments("--start-maximized");
WebDriver = new ChromeDriver(chromeOptions);
//WebDriver = new InternetExplorerDriver(new InternetExplorerOptions()
// {
// IntroduceInstabilityByIgnoringProtectedModeSettings = true,
// UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore
// });
WebDriver.Manage().Window.Maximize();
WebDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(VeryLongWait8));
}
示例10: StartDriver
public void StartDriver()
{
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--start-maximized");
switch (_browserName)
{
case BrowserNames.Chrome:
if (!_isUsingGrid)
{
_driver = new ChromeDriver(WebDriversDirectory, chromeOptions);
}
else
{
_capability.SetCapability(ChromeOptions.Capability, chromeOptions);
}
break;
case BrowserNames.Firefox:
if (!_isUsingGrid)
{
_driver = new FirefoxDriver(new FirefoxProfile{EnableNativeEvents = true});
_driver.Manage().Window.Maximize();
}
break;
case BrowserNames.InternetExplorer:
if (!_isUsingGrid)
{
var internetExplorerOptions = new InternetExplorerOptions
{
EnableNativeEvents = true
};
_driver = new InternetExplorerDriver(WebDriversDirectory,internetExplorerOptions);
_driver.Manage().Window.Maximize();
}
break;
case BrowserNames.Safari:
if (!_isUsingGrid)
{
_driver = new SafariDriver();
_driver.Manage().Window.Maximize();
}
break;
default:
throw new NotSupportedException("Unsupported browser.");
}
if (_isUsingGrid)
{
_capability.IsJavaScriptEnabled = true;
_driver = new ExtendedRemoteWebDriver(new Uri(Configuration.HubUrl), _capability);
_driver.Manage().Window.Maximize();
}
SetImplicitWait(Configuration.ImplicitWait);
}
示例11: CreateLocalDriver
public override IWebDriver CreateLocalDriver()
{
DriverType = WebDriverType.Chrome;
var driverService = ChromeDriverService.CreateDefaultService();
driverService.EnableVerboseLogging = true;
driverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
var capabilities = DesiredCapabilities.Chrome();
chromeOptions.AddArguments(new string[] { "test-type" });
capabilities.SetCapability(ChromeOptions.Capability, chromeOptions);
return new ChromeDriver(driverService, chromeOptions);
}
示例12: Login
public void Login()
{
var options = new ChromeOptions();
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability("chrome.switches", (object)("--start-maxisized"));
options.AddArguments("--test-type", "--start-maximized");
options.AddArguments("--test-type", "--ignore-certificate-errors");
options.BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var driver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);
//var ieoptions = new InternetExplorerOptions();
//DesiredCapabilities iecapabilities = DesiredCapabilities.InternetExplorer();
//iecapabilities.SetCapability("internetexplorer.switches", (object)("--start-maxisized"));
//ieoptions.AddAdditionalCapability("--test-type", "--start-maximized");
//ieoptions.AddAdditionalCapability("--test-type", "--ignore-certificate-errors");
//var iedriver = new InternetExplorerDriver(@"C:\Program Files (x86)\Internet Explorer");
driver.Navigate().GoToUrl(loginurl);
int timeout = 0;
while (driver.FindElements(By.ClassName("logbox")).Count == 0 && timeout < 500)
{
Thread.Sleep(1);
timeout++;
}
IWebElement element = driver.FindElement(By.ClassName("logbox"));
IWebElement ElName = element.FindElement(By.Name("username"));
ElName.Clear();
ElName.SendKeys(loginName);
IWebElement ElPassword = element.FindElement(By.Id("password"));
ElPassword.Clear();
ElPassword.SendKeys(loginPassword);
IWebElement ElLogin = element.FindElement(By.Id("IBtnLogin"));
ElLogin.Click();
}
示例13: CreateChromeOptions
private static ChromeOptions CreateChromeOptions(bool leaveBrowserRunning)
{
try
{
var options = new ChromeOptions
{
LeaveBrowserRunning = leaveBrowserRunning
};
options.AddArguments("start-maximized");
return options;
}
catch (Exception ex)
{
throw ex;
}
}
示例14: ScenarioBase
public ScenarioBase()
{
Debug.Listeners.Add(new DefaultTraceListener());
var browser = "Chrome";
if (browser == "Chrome")
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("chrome.switches", "--disable-extensions");
ActorBase.I = new ChromeDriver(options);
var opts = ActorBase.I.Manage();
opts.Window.Maximize();
}
else if (browser == "IE")
{
ActorBase.I = new InternetExplorerDriver();
var opts = ActorBase.I.Manage();
opts.Window.Maximize();
}
else if (browser == "Firefox")
{
ActorBase.I = new FirefoxDriver();
var opts = ActorBase.I.Manage();
opts.Window.Maximize();
}
else if (browser == "Safari")
{
ActorBase.I = new SafariDriver();
var opts = ActorBase.I.Manage();
opts.Window.Maximize();
}
else if (browser == "PhantomJS")
{
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
ActorBase.I = new PhantomJSDriver(driverService);
var opts = ActorBase.I.Manage();
opts.Window.Maximize();
}
}
示例15: CreateChromeDriver
public static IWebDriver CreateChromeDriver(string profileName, string path = null)
{
var chromeOptions = new ChromeOptions();
if (!string.IsNullOrWhiteSpace(profileName))
{
var fileChars = Path.GetInvalidFileNameChars();
var pathChars = Path.GetInvalidFileNameChars();
var invalidChars = fileChars.Union(pathChars);
profileName = String.Join("", profileName.Where(c => !invalidChars.Contains(c)));
chromeOptions.AddArguments(String.Format("user-data-dir=c:\\ChromeProfiles\\{0}", profileName));
}
ChromeDriver Driver;
if (!string.IsNullOrWhiteSpace(path))
{
//var service = ChromeDriverService.CreateDefaultService(path);
//service.EnableVerboseLogging = true;
//service.LogPath = "chromedriver.log";
Driver = new ChromeDriver(path, chromeOptions);
}
else
{
//var service = ChromeDriverService.CreateDefaultService();
//service.EnableVerboseLogging = true;
//service.LogPath = "chromedriver.log";
Driver = new ChromeDriver(chromeOptions);
}
Driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0, 1, 0));
Driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1));
Driver.Manage().Window.Maximize();
return Driver;
}