Get text from text field of type email?

删除回忆录丶 提交于 2019-12-14 02:26:23

问题


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="[^ @]*@[^ @]*">

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")

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

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


回答1:


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)



来源:https://stackoverflow.com/questions/25445816/get-text-from-text-field-of-type-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!