コード例 #1
0
        public async Task SwitchToFrame(string frameName, string element = null, bool doFocus = true, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (frameName == null)
            {
                if (element == null)
                {
                    await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false);

                    if (asyncFirefoxDriver.ClientMarionette == null)
                    {
                        throw new Exception("error: no clientMarionette");
                    }
                    var comm1 = new SwitchToFrameCommand(frameName, element, doFocus);
                    await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false);

                    if (comm1.Error != null)
                    {
                        throw new WebBrowserException(comm1.Error);
                    }
                }
                else
                {
                    await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false);

                    if (asyncFirefoxDriver.ClientMarionette == null)
                    {
                        throw new Exception("error: no clientMarionette");
                    }
                    var comm1 = new SwitchToFrameCommand(frameName, element, doFocus);
                    await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false);

                    if (comm1.Error != null)
                    {
                        throw new WebBrowserException(comm1.Error);
                    }
                }
            }
            else
            {
                string name = /*frameName; //*/ Regex.Replace(frameName, @"(['""\\#.:;,!?+<>=~*^$|%&@`{}\-/\[\]\(\)])", @"\$1");
                var    json = await asyncFirefoxDriver.Elements.FindElements("css selector", "frame[name='" + name + "'],iframe[name='" + name + "']").ConfigureAwait(false);

                var frameElements = FirefoxDriverElements.GetElementsFromResponse(json);
                if (frameElements.Count == 0)
                {
                    json = await asyncFirefoxDriver.Elements.FindElements("css selector", "frame#" + name + ",iframe#" + name).ConfigureAwait(false);

                    frameElements = FirefoxDriverElements.GetElementsFromResponse(json);
                    if (frameElements.Count == 0)
                    {
                        var e = new WebBrowserException("No frame element found with name or id " + frameName, "no such frame");
                        //e.Error = "No frame element found with name or id";
                        throw e; // NoSuchFrameException("No frame element found with name or id " + frameName);
                    }
                }

                await SwitchToFrame(null, frameElements[0], doFocus, cancellationToken).ConfigureAwait(false);
            }
        }
コード例 #2
0
        public async Task <string> GetActiveElement(CancellationToken cancellationToken = default(CancellationToken))
        {
            await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false);

            if (asyncFirefoxDriver.ClientMarionette == null)
            {
                throw new Exception("error: no clientMarionette");
            }
            var comm1 = new GetActiveElementCommand();
            await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false);

            if (comm1.Error != null)
            {
                throw new WebBrowserException(comm1.Error);
            }
            return(FirefoxDriverElements.GetElementFromResponse(comm1.Result));
        }
コード例 #3
0
 internal static string ElementId(JToken result)
 {
     return(FirefoxDriverElements.GetElementFromResponse(result));
 }