V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jahan
V2EX  ›  Python

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

  •  
  •   jahan · 2017-12-23 20:21:25 +08:00 · 3151 次点击
    这是一个创建于 2556 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <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 ?
    8 条回复    2017-12-25 10:18:20 +08:00
    jahan
        1
    jahan  
    OP
       2017-12-23 20:21:49 +08:00
    www.barchart.com 的登陆框。
    jahan
        2
    jahan  
    OP
       2017-12-23 20:38:34 +08:00
    find_elementsbyname 倒是可以找到,这个输入,不过为什么 xpath 不行,byclassname 也不行呢?
    sky48818
        3
    sky48818  
       2017-12-23 20:42:23 +08:00 via Android
    block
    wangyongbo
        4
    wangyongbo  
       2017-12-23 21:32:52 +08:00
    $x("//div[@class='form-group']/input[@name='email']")
    这个在 chrome 的 console 里面可以用。
    ysc3839
        5
    ysc3839  
       2017-12-24 02:38:04 +08:00 via Android
    form 有 ID,下面的第一个 input 就是了。
    shuizhengqi
        6
    shuizhengqi  
       2017-12-24 09:30:52 +08:00 via iPhone   ❤️ 1
    你这发的是什么玩意,我看着都 tm 累
    jahan
        7
    jahan  
    OP
       2017-12-24 09:49:01 +08:00
    @ysc3839 merry Xmas.好办法。
    dirls
        8
    dirls  
       2017-12-25 10:18:20 +08:00
    @wangyongbo chrome console 能找到,而程序 xpath 找不到,可能是页面 html 源码不标准,chrome 渲染时自动做了修正。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3975 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:14 · PVG 12:14 · LAX 20:14 · JFK 23:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.