當前位置: 首頁>>代碼示例>>C#>>正文


C# ChromeDriver.ElementIsPresent方法代碼示例

本文整理匯總了C#中OpenQA.Selenium.Chrome.ChromeDriver.ElementIsPresent方法的典型用法代碼示例。如果您正苦於以下問題:C# ChromeDriver.ElementIsPresent方法的具體用法?C# ChromeDriver.ElementIsPresent怎麽用?C# ChromeDriver.ElementIsPresent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenQA.Selenium.Chrome.ChromeDriver的用法示例。


在下文中一共展示了ChromeDriver.ElementIsPresent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        static void Main()
        {
            if (!File.Exists("settings.json"))
            {
                throw new Exception("settings.json file doesn't exist.");
            }

            settings = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText("settings.json"));

            if (string.IsNullOrWhiteSpace(settings["steamUsername"]) || string.IsNullOrWhiteSpace(settings["steamPassword"]))
            {
                throw new Exception("Please provide your Steam username and password in settings.json.");
            }

            var options = new ChromeOptions();
            options.AddArgument(string.Format("--user-data-dir={0}", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "userdata")));
            options.AddArgument("--enable-file-cookies");
            options.AddArgument("--disable-cache");

            driver = new ChromeDriver(options);

            directoryImgs = Path.Combine(directory, "images");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            else
            {
                Array.ForEach(Directory.GetFiles(directory, "*.html", SearchOption.TopDirectoryOnly), File.Delete);
                Array.ForEach(Directory.GetFiles(directoryImgs, "*.png", SearchOption.TopDirectoryOnly), File.Delete);
                Array.ForEach(Directory.GetFiles(directoryImgs, "*.jpg", SearchOption.TopDirectoryOnly), File.Delete);
                Array.ForEach(Directory.GetFiles(directoryImgs, "*.gif", SearchOption.TopDirectoryOnly), File.Delete);
            }

            driver.Navigate().GoToUrl("https://partner.steamgames.com/");

            if (driver.ElementIsPresent(By.ClassName("avatar")))
            {
                signedIn = true;
            }
            else
            {
                Login();
            }

            if (signedIn)
            {
                if (settings.Keys.Contains("predefinedDocs"))
                {
                    foreach (string predefined in settings["predefinedDocs"].Split(','))
                    {
                        var key = "https://partner.steamgames.com/documentation/" + predefined;

                        if (string.IsNullOrWhiteSpace(predefined) || documentationLinks.ContainsKey(key))
                        {
                            Console.WriteLine("Invalid or duplicate predefined doc: {0}", predefined);
                            continue;
                        }

                        cleanDocumentationLinks.Add(predefined);
                        documentationLinks.Add(key, false);
                    }
                }

                driver.Navigate().GoToUrl("https://partner.steamgames.com/home/steamworks");

                GetDocumentationLinks();

                AddFromSearchResults();

                FetchLinks();
            }

            driver.Quit();

            settings["predefinedDocs"] = string.Join(",", cleanDocumentationLinks);

            File.WriteAllText("settings.json", JsonConvert.SerializeObject(settings, Formatting.Indented));

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
開發者ID:TomasDuda,項目名稱:SteamDocsScraper,代碼行數:83,代碼來源:Program.cs


注:本文中的OpenQA.Selenium.Chrome.ChromeDriver.ElementIsPresent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。