本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeOptions类的典型用法代码示例。如果您正苦于以下问题:C# ChromeOptions类的具体用法?C# ChromeOptions怎么用?C# ChromeOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChromeOptions类属于OpenQA.Selenium.Chrome命名空间,在下文中一共展示了ChromeOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestHappyPathChrome
public void TestHappyPathChrome()
{
ChromeOptions co = new ChromeOptions();
co.AddArgument("--test-type");
ChromeDriver cd = new ChromeDriver("C:\\Users\\ehelin\\Downloads\\chromedriver_win32", co);
TestHappyPath(cd);
}
示例2: 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();
}
示例3: Launch
internal void Launch(bool mobile, string url = "https://www.bing.com/") {
Quit();
_viewModel.ResetProfileCommand.RaiseCanExecuteChanged();
ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("user-data-dir=" + App.Folder + "profile");
if (mobile)
options.EnableMobileEmulation("Google Nexus 5");
try {
_driver = new ChromeDriver(service, options);
_driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
_builder = new Actions(_driver);
LogUpdate("Launching Chrome " + (mobile ? "Mobile" : "Desktop"), Colors.CadetBlue);
if (url != null)
_driver.Navigate().GoToUrl(url);
}
catch (Exception ex) {
LogUpdate("Error Launching Chrome " + (mobile ? "Mobile" : "Desktop") + "\r\n" + ex.Message, Colors.Red);
service.Dispose();
}
}
示例4: 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;
}
示例5: CreateDriver
public static IWebDriver CreateDriver()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--disable-cache");
var driver = new ChromeDriver(options);
return driver;
}
示例6: Start
public void Start()
{
var options = new ChromeOptions();
options.AddArgument("--test-type");
Instance = new RemoteWebDriver(ChromeDriver.BaseUrl, options.ToCapabilities());
}
示例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: InboxModel
public InboxModel(string username, string password, BackgroundWorker bw, bool tv)
{
ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("user-data-dir=" + App.Folder + "profileIB");
IWebDriver driver = new ChromeDriver(service, options);
driver.Navigate().GoToUrl("http://www.inboxdollars.com");
try
{
driver.FindElement(By.Id("loginname")).Clear();
driver.FindElement(By.Id("pwd")).Clear();
driver.FindElement(By.Id("loginname")).SendKeys(username);
driver.FindElement(By.Id("pwd")).SendKeys(password);
Helpers.wait(1000);
driver.FindElement(By.ClassName("submit2")).Click();
}
catch { }
try
{
if (driver.FindElement(By.Id("emailsBlock")).FindElement(By.ClassName("textBox")).Text != "0")
{
driver.FindElement(By.Id("emailsBlock")).FindElement(By.ClassName("textBox")).Click();
}
}
catch { }
if (!tv)
{
try
{
driver.FindElement(By.ClassName("videos")).Click();
videos(driver);
}
catch { }
}
else if (tv)
{
try
{
driver.FindElement(By.ClassName("tv")).Click();
Helpers.wait(2000);
Helpers.ByClass(driver, "jw-icon");
while (true)
{
try
{
driver.FindElement(By.Id("tvStillTherePopupContinue")).Click();
}
catch { }
}
}
catch { }
}
}
示例9: GetChromeOptions
private static ChromeOptions GetChromeOptions()
{
ChromeOptions option = new ChromeOptions();
option.AddArgument("start-maximized");
option.Proxy = null;
return option;
}
示例10: 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;
}
}
}
示例11: 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));
}
示例12: StartDriver
public static IWebDriver StartDriver (string browserType)
{
Trace.WriteLine("Start browser: '" + browserType + "'");
IWebDriver driver = null;
switch (browserType)
{
case "ie":
{
driver = new InternetExplorerDriver("Drivers");
break;
}
case "firefox":
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.EnableNativeEvents = true;
firefoxProfile.AcceptUntrustedCertificates = true;
driver = new FirefoxDriver(firefoxProfile);
break;
}
case "chrome":
{
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--disable-keep-alive");
driver = new ChromeDriver("Drivers", chromeOptions);
break;
}
}
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
driver.Manage().Window.Maximize();
return driver;
}
示例13: GetDriver
public static IWebDriver GetDriver(DriverType typeOfDriver)
{
IWebDriver browser;
switch (typeOfDriver)
{
// NOTE REMOTE DRIVER IS NOT SUPPORTED
case DriverType.Chrome:
ChromeOptions co = new ChromeOptions();
browser = new ChromeDriver();
break;
case DriverType.IE:
InternetExplorerOptions ieo = new InternetExplorerOptions();
browser = new InternetExplorerDriver();
break;
case DriverType.Firefox:
default:
FirefoxProfile ffp = new FirefoxProfile();
ffp.AcceptUntrustedCertificates = true;
ffp.Port = 8181;
browser = new FirefoxDriver(ffp);
break;
}
return browser;
}
示例14: GetChromeOptions
private static ChromeOptions GetChromeOptions()
{
var option = new ChromeOptions();
option.AddArgument("start-maximized");
option.AddExtension(@"C:\downloads\GoogleAnalytics.crx");
option.Proxy = null;
return option;
}
示例15: GetChromeOptions
private static ChromeOptions GetChromeOptions()
{
ChromeOptions option = new ChromeOptions();
option.AddArgument("start-maximized");
// option.AddExtension(@"C:\Users\rahul.rathore\Desktop\Cucumber\extension_3_0_12.crx");
return option;
}