コード例 #1
0
        public static void Main()
        {
            using (IEngine engine = EngineFactory.Create())
            {
                using (IBrowser browser = engine.CreateBrowser())
                {
                    browser.Navigation.LoadUrl(Path.GetFullPath("html.html")).Wait();
                    IWebStorage webStorage = browser.MainFrame.LocalStorage;

                    // Read and display the 'myKey' storage value.
                    Console.Out.WriteLine($"The initial myKey value: {webStorage["myKey"]}");

                    // Modify the 'myKey' storage value.
                    webStorage["myKey"] = "Hello from Local Storage";

                    string updatedValue = browser
                                          .MainFrame.ExecuteJavaScript <IJsObject>("window")
                                          .Result.Invoke <string>("myFunction");

                    Console.Out.WriteLine($"The updated myKey value: {updatedValue}");
                }
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
コード例 #2
0
 public RemoteWebDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
 {
     this.executor = commandExecutor;
     this.StartClient();
     this.StartSession(desiredCapabilities);
     this.mouse    = new RemoteMouse(this);
     this.keyboard = new RemoteKeyboard(this);
     if (this.capabilities.HasCapability(CapabilityType.SupportsApplicationCache))
     {
         object capability = this.capabilities.GetCapability(CapabilityType.SupportsApplicationCache);
         if (capability is bool && (bool)capability)
         {
             this.appCache = new RemoteApplicationCache(this);
         }
     }
     if (this.capabilities.HasCapability(CapabilityType.SupportsLocationContext))
     {
         object capability2 = this.capabilities.GetCapability(CapabilityType.SupportsLocationContext);
         if (capability2 is bool && (bool)capability2)
         {
             this.locationContext = new RemoteLocationContext(this);
         }
     }
     if (this.capabilities.HasCapability(CapabilityType.SupportsWebStorage))
     {
         object capability3 = this.capabilities.GetCapability(CapabilityType.SupportsWebStorage);
         if (capability3 is bool && (bool)capability3)
         {
             this.storage = new RemoteWebStorage(this);
         }
     }
 }
コード例 #3
0
ファイル: WebDriver.cs プロジェクト: nickgaya/selenium
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDriver"/> class.
        /// </summary>
        /// <param name="executor">The <see cref="ICommandExecutor"/> object used to execute commands.</param>
        /// <param name="capabilities">The <see cref="ICapabilities"/> object used to configuer the driver session.</param>
        protected WebDriver(ICommandExecutor executor, ICapabilities capabilities)
        {
            this.executor = executor;
            this.StartSession(capabilities);
            this.elementFactory = new WebElementFactory(this);
            this.network        = new NetworkManager(this);
            this.registeredCommands.AddRange(DriverCommand.KnownCommands);

            if ((this as ISupportsLogs) != null)
            {
                // Only add the legacy log commands if the driver supports
                // retrieving the logs via the extension end points.
                this.RegisterDriverCommand(DriverCommand.GetAvailableLogTypes, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/se/log/types"), true);
                this.RegisterDriverCommand(DriverCommand.GetLog, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/se/log"), true);
            }

            // These below code exists solely to support obsolete protocol end points.
            // They should be removed at the earliest available opportunity.
            if (this.Capabilities.HasCapability(CapabilityType.SupportsApplicationCache))
            {
                object appCacheCapability = this.Capabilities.GetCapability(CapabilityType.SupportsApplicationCache);
                if (appCacheCapability is bool && (bool)appCacheCapability)
                {
                    this.appCache = new ApplicationCache(this);
                }
            }

            if (this.Capabilities.HasCapability(CapabilityType.SupportsLocationContext))
            {
                object locationContextCapability = this.Capabilities.GetCapability(CapabilityType.SupportsLocationContext);
                if (locationContextCapability is bool && (bool)locationContextCapability)
                {
                    this.locationContext = new LocationContext(this);
                }
            }

            if (this.Capabilities.HasCapability(CapabilityType.SupportsWebStorage))
            {
                object webContextCapability = this.Capabilities.GetCapability(CapabilityType.SupportsWebStorage);
                if (webContextCapability is bool && (bool)webContextCapability)
                {
                    this.storage = new WebStorage(this);
                }
            }
        }
コード例 #4
0
        public static void Main()
        {
            try
            {
                using (IEngine engine = EngineFactory.Create(new EngineOptions.Builder().Build()))
                {
                    Console.WriteLine("Engine created");

                    using (IBrowser browser = engine.CreateBrowser())
                    {
                        Console.WriteLine("Browser created");

                        browser.MainFrame
                        .LoadHtml(new LoadHtmlParameters("<html><body>"
                                                         + "<script>localStorage.myKey = \"Initial Value\";"
                                                         + "function myFunction(){return localStorage.myKey;}"
                                                         + "</script></body></html>"
                                                         )
                        {
                            BaseUrl = "https://teamdev.com",
                            Replace = true
                        })
                        .Wait();
                        IWebStorage webStorage = browser.MainFrame.LocalStorage;
                        // Read and display the 'myKey' storage value.
                        Console.Out.WriteLine("The initial myKey value: " + webStorage["myKey"]);
                        // Modify the 'myKey' storage value.
                        webStorage["myKey"] = "Hello from Local Storage";
                        string updatedValue = browser.MainFrame.ExecuteJavaScript <IJsObject>("window")
                                              .Result.Invoke <string>("myFunction");
                        Console.Out.WriteLine("The updated myKey value: " + updatedValue);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to terminate...");
            Console.ReadKey();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: PIM4/integriert
            public WindowMain()
            {
                BrowserContext browserContext = BrowserContext.DefaultContext;

                Browser browser = BrowserFactory.Create(browserContext);

                browser.DocumentLoadedInMainFrameEvent += delegate
                {
                    IWebStorage webStorage = browser.GetLocalWebStorage();
                    // Read and display the 'myKey' storage value.
                    Console.Out.WriteLine("The myKey value: " + webStorage["myKey"]);
                    // Modify the 'myKey' storage value.
                    webStorage.Set("myKey", "Hello from Local Storage");
                };

                browserView = new WPFBrowserView(browser);
                Content     = browserView;

                Width        = 1024;
                Height       = 768;
                this.Loaded += WindowMain_Loaded;
            }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RemoteWebDriver"/> class
        /// </summary>
        /// <param name="commandExecutor">An <see cref="ICommandExecutor"/> object which executes commands for the driver.</param>
        /// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
        public RemoteWebDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
        {
            this.executor = commandExecutor;
            this.StartClient();
            this.StartSession(desiredCapabilities);
            this.mouse = new RemoteMouse(this);
            this.keyboard = new RemoteKeyboard(this);

            if (this.capabilities.HasCapability(CapabilityType.SupportsApplicationCache))
            {
                object appCacheCapability = this.capabilities.GetCapability(CapabilityType.SupportsApplicationCache);
                if (appCacheCapability is bool && (bool)appCacheCapability)
                {
                    this.appCache = new RemoteApplicationCache(this);
                }
            }

            if (this.capabilities.HasCapability(CapabilityType.SupportsLocationContext))
            {
                object locationContextCapability = this.capabilities.GetCapability(CapabilityType.SupportsLocationContext);
                if (locationContextCapability is bool && (bool)locationContextCapability)
                {
                this.locationContext = new RemoteLocationContext(this);
                }
            }

            if (this.capabilities.HasCapability(CapabilityType.SupportsWebStorage))
            {
                object webContextCapability = this.capabilities.GetCapability(CapabilityType.SupportsWebStorage);
                if (webContextCapability is bool && (bool)webContextCapability)
                {
                    this.storage = new RemoteWebStorage(this);
                }
            }
        }
コード例 #7
0
ファイル: RemoteWebDriver.cs プロジェクト: petruc/selenium
 /// <summary>
 /// Initializes a new instance of the RemoteWebDriver class
 /// </summary>
 /// <param name="commandExecutor">An <see cref="ICommandExecutor"/> object which executes commands for the driver.</param>
 /// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
 public RemoteWebDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
 {
     this.executor = commandExecutor;
     this.StartClient();
     this.StartSession(desiredCapabilities);
     this.mouse = new RemoteMouse(this);
     this.keyboard = new RemoteKeyboard(this);
     this.storage = new RemoteWebStorage(this);
     this.appCache = new RemoteApplicationCache(this);
     this.locationContext = new RemoteLocationContext(this);
 }