根据内容查找登录表单 [英] finding the login form based on content

查看:204
本文介绍了根据内容查找登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想找出HTML文档中有多个forms登录表单.我的猜测如下:如果我可以识别'forgot your password''Remember me''keep me signed in'这样的表单字符串属于哪个形式,那可能是登录表单,因为这样的字符串/链接出现在密码字段之后.

Basically I want to find out the login form when there are multiple forms on a HTML document. My guess is as following: What if i can identify to which form strings like 'forgot your password' or 'Remember me' or 'keep me signed in' belongs then it might be login form since such strings/link appear after the password field.

有什么办法可以找出包含这些字符串/链接的表单,然后在我的应用程序中使用该表单的名称或ID?

Is there any way i can find out which form contains these strings/links and then use that form 's name or ID in my app ?

更新:我使用以下代码获取包含字符串忘记密码"的表单ID,但未返回任何内容.

Update: I used following code to get form ID which contains strings 'forgot your password' but it returns nothing.

NSString *formID = [NSString stringWithFormat:@"%@",[self.browser stringByEvaluatingJavaScriptFromString:@"$('form').filter (function() {var text = this.innerHTML.toLowerCase();" 
                        "return text.indexOf('forgot your password') != -1 || "
                        "text.indexOf('remember me') != -1;}).attr('id');"] ];

推荐答案

var loginFormId = $('form').filter(function() {
    return this.innerHTML.indexOf('forgot your password') != -1;
}).attr('id');​

或仅使用:contains:

var loginFormId = $('form:contains("forgot your password")').attr('id');​

:contains选择器文档:

描述:选择包含指定文本的所有元素. 匹配的文本可以直接出现在所选元素中,该元素的任何后代或其组合中.与属性值选择器一样,:contains()括号内的文本可以写为裸词,也可以用引号引起来.文本必须具有匹配的大小写才能选择.

Description: Select all elements that contain the specified text. The matching text can appear directly within the selected element, in any of that element's descendants, or a combination thereof. As with attribute value selectors, text inside the parentheses of :contains() can be written as a bare word or surrounded by quotation marks. The text must have matching case to be selected.

实时演示

更新:

如果不确定文本的大小写,则必须使用filter:

If you are not sure about the case of the text, you must use filter:

var theFormId = $('form').filter(function() {
    var text = this.innerHTML.toLowerCase(); 
    return text.indexOf('forgot your password') != -1 || 
           text.indexOf('remember me') != -1;

这篇关于根据内容查找登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆