这个 username 输入框该用什么定位呢?

2017-12-23 20:21:25 +08:00
 jahan
<div>
<form novalidate="" name="loginForm" id="bc-login-form" class="bc-form bc-login-form ng-pristine ng-invalid ng-invalid-required" data-ng-submit="login(loginForm)">
<div class="form-group" data-ng-class="{'error-input':loginForm.email.$invalid &amp;&amp; loginForm.$submitted}">
<input type="text" class="form-input form-field-login ng-pristine ng-invalid ng-invalid-required ng-touched placeholder" data-ng-class="{'remove-chrome-highlight':loginForm.email.$invalid &amp;&amp; loginForm.$submitted}" placeholder="Login with email" name="email" autofocus="" required="" data-ng-model="user.email">
</div>
<div class="form-group group-pass-submit row collapse">
<div class="small-10 columns field-password-wrapper small-12" data-ng-class="{'error-input':loginForm.password.$invalid &amp;&amp; loginForm.$submitted, 'small-12': !ref}">
<input type="password" data-hj-masked="" id="login-form-password" data-ng-class="{'remove-chrome-highlight':loginForm.password.$invalid &amp;&amp; loginForm.$submitted}" class="form-input form-field-password ng-pristine ng-untouched ng-invalid ng-invalid-required" placeholder="Password" name="password" required="" data-ng-model="user.password">
<span password-id="'login-form-password'" class="peek-at-password">show</span>
</div>
<!-- ngIf: ref -->
</div>
<div class="form-group row collapse form-extra-nav">
<div class="small-6 columns">
<div class="input-checkbox">
<input id="rememeber_me" name="rememeber_me" data-ng-model="user.remember" type="checkbox" checked="checked" class="ng-pristine ng-untouched ng-valid">
<label for="rememeber_me">
<span class="bc-glyph-check"></span>
Remember Me
</label>
</div>
</div>
<div class="small-6 columns forgot-pass-link">
<a href="" data-ng-click="goToForgot()">Forgot Password?</a>
</div>
</div>
<div id="g-login-component" class="g-recaptcha"></div>
<div>
<div class="error-block ng-hide" data-ng-show="hasErrors" data-form="loginForm" data-errors="errors">
<p class="error-text" data-ng-show="form.$error.required">
Complete required fields to continue.
</p>
<p class="error-text ng-hide" data-ng-show="form.email.$invalid &amp;&amp; !form.email.$error.required">
Enter a valid email.
</p>
<p class="error-text ng-hide" data-ng-show="form.$error.invalidCaptcha">
Please complete the reCAPTCHA to continue.
</p>
<p class="error-text ng-hide" data-ng-show="errors.required_captcha">
Please complete the reCAPTCHA to continue.
</p>
<p class="error-text ng-hide" data-ng-show="form.$error.invalidEmail">
Please enter a valid email
</p>
<p class="error-text ng-hide" data-ng-show="form.$error.invalidOneword">
Only one value is allowed.
</p>
<p class="error-text ng-hide" data-ng-show="errors.server_error">
Oops, something went wrong. Please refresh the page and try again.
</p>
<p class="error-text ng-hide" data-ng-show="form.password.$error.minlength &amp;&amp; !form.password.$error.required">
Password must be at least 6 characters.
</p>
<p class="error-text ng-hide" data-ng-show="errors.recaptcha">
Please complete the reCAPTCHA to continue.
</p>
<!-- ngIf: errors.email_does_not_exist -->
<p class="error-text ng-hide" data-ng-show="errors.password_email_does_not_exist">
We could not locate an account that uses this email address. Try again, <a data-bc-go-to-register="">create an account</a>, or <a href="/contact"> contact our support team for assistance.</a>
</p>

<p class="error-text ng-binding ng-hide" data-ng-show="errors.email" data-bc-bind-unsafe="errors.email"></p>
<p class="error-text ng-hide" data-ng-show="errors.default" data-ng-bind-html="errors.default">false</p>
<p class="error-text ng-binding ng-hide" data-ng-show="errors.unsafe_default" data-bc-bind-unsafe="errors.unsafe_default"></p>
<p class="error-text ng-binding ng-hide" data-ng-show="errors.password_does_not_match" data-bc-bind-unsafe="errors.password_does_not_match"></p>
<p class="error-text ng-hide" data-ng-show="errors.not_found" data-ng-bind-html="errorMessages.not_found"></p>
<p class="error-text js-incomplete ng-hide" data-ng-show="errors.incomplete"></p>
<!-- ngIf: errors.password_incomplete -->
</div>
</div>
<!-- ngIf: !ref --><div data-ng-if="!ref" class="form-group text-center">
<button type="submit" class="bc-button light-blue full-width-login-btn">Log In</button>
</div><!-- end ngIf: !ref -->
</form>
</div>


======================
上面的 password 比较好定位,就是 username 用 byclassname=orm-input form-field-login ng-pristine ng-invalid ng-invalid-required ng-touched placeholder 定位不了,用 //div[@class='form-group']/input[name()='email']也不行,该如何定位呢。居然 username 没有 id ?
3136 次点击
所在节点    Python
8 条回复
jahan
2017-12-23 20:21:49 +08:00
www.barchart.com 的登陆框。
jahan
2017-12-23 20:38:34 +08:00
find_elementsbyname 倒是可以找到,这个输入,不过为什么 xpath 不行,byclassname 也不行呢?
sky48818
2017-12-23 20:42:23 +08:00
block
wangyongbo
2017-12-23 21:32:52 +08:00
$x("//div[@class='form-group']/input[@name='email']")
这个在 chrome 的 console 里面可以用。
ysc3839
2017-12-24 02:38:04 +08:00
form 有 ID,下面的第一个 input 就是了。
shuizhengqi
2017-12-24 09:30:52 +08:00
你这发的是什么玩意,我看着都 tm 累
jahan
2017-12-24 09:49:01 +08:00
@ysc3839 merry Xmas.好办法。
dirls
2017-12-25 10:18:20 +08:00
@wangyongbo chrome console 能找到,而程序 xpath 找不到,可能是页面 html 源码不标准,chrome 渲染时自动做了修正。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/417115

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX