Exemplo n.º 1
0
        /// <summary>
        /// Gets a collection of elements by id.
        /// </summary>
        /// <param name="id">The id of the element.</param>
        /// <returns>Collection of elements for the given <paramref name="id"/>.</returns>
        protected IEnumerable <INativeElement> GetElementsByIdImpl(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            Initialize();

            if (!clientPort.HasJavaScriptSupportForQuerySelector)
            {
                var elementReference  = clientPort.CreateVariableName();
                var documentReference = GetDocumentReference(containerReference);
                var command           = string.Format("{0} = {1}.getElementById(\"{2}\"); {0} != null", elementReference, documentReference, id);
                if (clientPort.WriteAndReadAsBool(command))
                {
                    yield return(new JSElement(clientPort, elementReference));
                }
            }
            else
            {
                var command    = string.Format("{0}.querySelectorAll(\"[Id='{1}']\")", containerReference, id);
                var ffElements = GetElementArrayEnumerator(command);
                foreach (var ffElement in ffElements)
                {
                    yield return(ffElement);
                }
            }
        }