Ejemplo n.º 1
0
        private void SetFillScriptForFocus(IDictionary <string, PageDetails.Field> filledFields)
        {
            if (!filledFields.Any())
            {
                return;
            }

            PageDetails.Field lastField = null, lastPasswordField = null;
            foreach (var field in filledFields)
            {
                if (field.Value.Viewable)
                {
                    lastField = field.Value;
                    if (field.Value.Type == "password")
                    {
                        lastPasswordField = field.Value;
                    }
                }
            }

            // Prioritize password field over others.
            if (lastPasswordField != null)
            {
                Script.Add(new List <string> {
                    "focus_by_opid", lastPasswordField.OpId
                });
            }
            else if (lastField != null)
            {
                Script.Add(new List <string> {
                    "focus_by_opid", lastField.OpId
                });
            }
        }
Ejemplo n.º 2
0
        private PageDetails.Field FindUsernameField(PageDetails pageDetails, PageDetails.Field passwordField, bool canBeHidden,
                                                    bool checkForm)
        {
            PageDetails.Field usernameField = null;

            foreach (var f in pageDetails.Fields)
            {
                if (f.ElementNumber >= passwordField.ElementNumber)
                {
                    break;
                }

                if ((!checkForm || f.Form == passwordField.Form) &&
                    (canBeHidden || f.Viewable) &&
                    f.ElementNumber < passwordField.ElementNumber &&
                    (f.Type == "text" || f.Type == "email" || f.Type == "tel"))
                {
                    usernameField = f;

                    if (FindMatchingFieldIndex(f, _usernameFieldNames) > -1)
                    {
                        // We found an exact match. No need to keep looking.
                        break;
                    }
                }
            }

            return(usernameField);
        }
Ejemplo n.º 3
0
        private bool FieldIsFuzzyMatch(PageDetails.Field field, List <string> names)
        {
            if (!string.IsNullOrWhiteSpace(field.HtmlId) && FuzzyMatch(names, field.HtmlId.ToLower()))
            {
                return(true);
            }
            if (!string.IsNullOrWhiteSpace(field.HtmlName) && FuzzyMatch(names, field.HtmlName.ToLower()))
            {
                return(true);
            }
            if (!string.IsNullOrWhiteSpace(field.LabelTag) && FuzzyMatch(names, CleanLabel(field.LabelTag)))
            {
                return(true);
            }
            if (!string.IsNullOrWhiteSpace(field.Placeholder) && FuzzyMatch(names, field.Placeholder.ToLower()))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        private int FindMatchingFieldIndex(PageDetails.Field field, string[] names)
        {
            var matchingIndex = -1;

            if (!string.IsNullOrWhiteSpace(field.HtmlId))
            {
                matchingIndex = Array.IndexOf(names, field.HtmlId.ToLower());
            }
            if (matchingIndex < 0 && !string.IsNullOrWhiteSpace(field.HtmlName))
            {
                matchingIndex = Array.IndexOf(names, field.HtmlName.ToLower());
            }
            if (matchingIndex < 0 && !string.IsNullOrWhiteSpace(field.LabelTag))
            {
                matchingIndex = Array.IndexOf(names, CleanLabel(field.LabelTag));
            }
            if (matchingIndex < 0 && !string.IsNullOrWhiteSpace(field.Placeholder))
            {
                matchingIndex = Array.IndexOf(names, field.Placeholder.ToLower());
            }

            return(matchingIndex);
        }