从电子邮件类型的文本字段中获取文本? [英] Get text from text field of type email?

查看:40
本文介绍了从电子邮件类型的文本字段中获取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想用 C# 阅读一个网站.我有它,所以它打开一个网站并去阅读一个 TextField.但是该网站有这样的文本字段.

So I am trying to read a site with C#. I have it so it opens a website and goes to read a TextField. However the website has the text field like so.

<input name="loginMail" class="c-txtfld c-txtfld-fixed c-txtfld-green c-txtfld-medium" id="login-email" type="email" placeholder="Email address" pattern="[^ @]*@[^ @]*">

因此,我可以让 C# 阅读它.

And because of this I can get C# to read it.

TextField emailaddressfield = this.Document.TextField(Find.BySelector("form#login-form.credential-form input#login-email")

但是,如果我将 type 属性编辑为 text,它将起作用.

It will work however if I edit the type attribute to text.

我想将其保留为 email.我怎么能这样读?

I want to keep this as email. How can I read it like that?

推荐答案

可以从现有的 WatiN 控件 (HTML) 创建自定义控件.为了获得 email 类型的文本字段值,我们需要创建一个 TextField 类型的自定义控件.请尝试以下代码.

It is possible to create a custom control from existing WatiN controls (HTML). In order to get text field value of type email, we need to create a custom control which would be of type TextField. Please try below code.

[ElementTag("input", InputType = "email", Index = 5)]    
public class EmailTextField : Element<EmailTextField>
{
    public EmailTextField(DomContainer domContainer, ElementFinder finder): base(domContainer, finder)
    { }
    public EmailTextField(DomContainer domContainer, INativeElement element): base(domContainer, element)
    { }
}

EmailTextField emailaddressfield = this.Document.EmailTextField(Find.BySelector("form#login-form.credential-form input#login-email")

(伪代码 - 未遵守)

(Pseudo code - not complied)

这篇关于从电子邮件类型的文本字段中获取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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