html form - HtmlUnit: how to get password field when getInputByName/Value are not possible? -



html form - HtmlUnit: how to get password field when getInputByName/Value are not possible? -

i writing little programme download blog articles, of protected username , password. that's htmlunit comes play. public articles, have no problem. protected articles, need log in using htmlunit. host page not provide name or value attributes in htmlform. next snippet of html code of host page.

<form id="notlogin" tabindex="6" method="post" action="#" onsubmit="return false" style="outline: none;"> <div class="login-form-top"><input autocomplete="off" tabindex="7" id="loginname" type="text" name="loginname" value="" class="login-mod-input" placeholder="微博/博客/邮箱/手机号"><input id="loginpass" tabindex="8" type="password" name="" value="" class="login-mod-input" placeholder="请输入密码"></div> </form>

as can see, loginpass there no name or value me locate password field. have written next relevant part.

final htmlform loginform = (htmlform) page.getfirstbyxpath("//form[@id='notlogin']"); system.out.println(loginform); final htmltextinput usrnhtmltextinput = loginform.getinputbyname("loginname"); usrnhtmltextinput.setvalueattribute(username); system.out.println(usrnhtmltextinput); final htmlpasswordinput pwdinput = loginform.getinputbyname("password"); pwdinput.setvalueattribute(password); system.out.println(pwdinput); final htmlpage page2 = (htmlpage) loginform.getinputbyvalue("登录").click(); system.out.println(page2);

could please point out me how can locate password input field in case?

thanks in advance! xi.

both inputs have id. id uniquely identifies element in dom. it's easiest , fastest way element:

htmlinput logininput = page.gethtmlelementbyid("loginname"); htmlinput passwordinput = page.gethtmlelementbyid("loginpass");

relevant api doc.

html-form htmlunit

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -