本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeOptions.ToCapabilities方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeOptions.ToCapabilities方法的具体用法?C# ChromeOptions.ToCapabilities怎么用?C# ChromeOptions.ToCapabilities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeOptions
的用法示例。
在下文中一共展示了ChromeOptions.ToCapabilities方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Start
public void Start()
{
var options = new ChromeOptions();
options.AddArgument("--test-type");
Instance = new RemoteWebDriver(ChromeDriver.BaseUrl, options.ToCapabilities());
}
示例3: CrawlFirstPage
private static void CrawlFirstPage(Uri startUrl)
{
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
var _driver = new RemoteWebDriver(_options.RemoteHubUrl, chromeOptions.ToCapabilities());
try
{
_driver.Navigate().GoToUrl(startUrl);
SaveHtmlAndScreenShot(startUrl, _driver);
pageVisitedURLMapping.TryAdd(startUrl, startUrl);
_driver.Close();
_driver.Quit();
}
catch (Exception ex)
{
logger.Info(" Thread : " + startUrl.PathAndQuery + " Error at " + ex.StackTrace);
_driver.Close();
_driver.Quit();
}
}
示例4: ChromeDriver
/// <summary>
/// Initializes a new instance of the <see cref="ChromeDriver"/> class using the specified <see cref="ChromeDriverService"/>.
/// </summary>
/// <param name="service">The <see cref="ChromeDriverService"/> to use.</param>
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
: base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
{
}
示例5: ConvertOptionsToCapabilities
private static ICapabilities ConvertOptionsToCapabilities(ChromeOptions options)
{
if (options == null)
{
throw new ArgumentNullException("options", "options must not be null");
}
return options.ToCapabilities();
}
示例6: CrawlPage
public static void CrawlPage(Uri startUrl)
{
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
chromeOptions.AddArgument("user-data-dir=C:/Debug/" + startUrl.AbsolutePath);
var _driver = new RemoteWebDriver(_options.RemoteHubUrl, chromeOptions.ToCapabilities());
try
{
ConcurrentDictionary<Uri, Uri> pageToVisit = new ConcurrentDictionary<Uri, Uri>();
ConcurrentDictionary<Uri, Uri> PartThreading;
pageToVisit.TryAdd(startUrl, null);
while (true && pageToVisit.Count > 0)
{
PartThreading = new ConcurrentDictionary<Uri, Uri>();
logger.Info(_options.Name + " Thread : " + startUrl.PathAndQuery + " Page To Visit Size :{0}", pageToVisit.Count + " SessionId" + _driver.SessionId );
foreach (var pTV in pageToVisit)
{
PartThreading.TryAdd(pTV.Key, pTV.Value);
Uri value;
pageToVisit.TryRemove(pTV.Key, out value);
}
foreach (var Key in PartThreading.Keys)
{
_driver.Navigate().GoToUrl(Key);
SaveHtmlAndScreenShot(Key, _driver);
pageToVisit = GetUnvisitedLinks(_driver, Key, _driver.Url, PartThreading, pageToVisit, startUrl);
pageVisitedURLMapping.TryAdd(Key, PartThreading[Key]);
ValidatePage(_driver, Key, PartThreading[Key]);
}
logger.Info(" Thread : " + startUrl.PathAndQuery + " Page Finish Visit Size :{0}", pageVisitedURLMapping.Count);
}
_driver.Close();
_driver.Quit();
}
catch (Exception ex)
{
logger.Info(" Thread : " + startUrl.PathAndQuery + " Error at " + ex.StackTrace);
_driver.Close();
_driver.Quit();
}
}
示例7: InitializeChromeDriver
public static RemoteWebDriver InitializeChromeDriver(Uri serviceUrl)
{
ChromeOptions options = new ChromeOptions();
var perfLoggingPrefs = new Dictionary<string, object> { { "enableNetwork", true }, { "enablePage", true }, { "enableTimeline", false } };
try
{
string perf = ConfigurationManager.AppSettings["ChromeDriver.PerfLogging"];
if ("false" != perf.ToLower())
{
options.AddAdditionalCapability("perfLoggingPrefs", perfLoggingPrefs);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
// Swallow non-existent Configurations
}
try
{
string mobile = ConfigurationManager.AppSettings["ChromeDriver.MobileEmulationDevice"];
if ("false" != mobile.ToLower())
{
options.AddAdditionalCapability("mobileEmulation",
new Dictionary<string, object> {{"deviceName", mobile}});
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
// Swallow non-existent Configurations
}
try
{
options.AddArgument("--lang=" + ConfigurationManager.AppSettings["ChromeDriver.language"]);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
// Swallow non-existent Configurations
}
DesiredCapabilities capabilities = options.ToCapabilities() as DesiredCapabilities;
var loggingPrefs = new Dictionary<string, object> { { "performance", "ALL" }, { "browser", "ALL" } };
try
{
string perf = ConfigurationManager.AppSettings["ChromeDriver.PerfLogging"];
if ("false" != perf.ToLower())
{
capabilities.SetCapability("loggingPrefs", loggingPrefs);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
// Swallow non-existent Configurations
}
return new RemoteWebDriver(serviceUrl, capabilities);
}