Macaca 请教一下关于微信里面 webview 元素的定位方法

boafantasy · 2017年06月08日 · 最后由 boafantasy 回复于 2017年06月09日 · 1132 次阅读

使用的是 python 库,看到官方文档里面只提供了

“id”
“xpath”
“link text”
“partial link text”
“tag name”
“class name”
“css selector”

几种方法,目前只会使用 tag name 来定位,想问问,类似这种 html 怎么定位比较好

<div _ngcontent-rsq-3="" class="login-box" role="login">
        <div _ngcontent-rsq-3="">
            <input _ngcontent-rsq-3="" placeholder="请输入用户名" type="text">
        </div>
        <div _ngcontent-rsq-3="" style="position: relative">
            <input _ngcontent-rsq-3="" placeholder="请输入密码" type="password">
            <i _ngcontent-rsq-3="" class="iconfont show-pwd"></i>
        </div>
        <div _ngcontent-rsq-3="" class="login-btn">
          <button _ngcontent-rsq-3="" disabled="">登 录</button>
        </div>
    </div>

目前我定位的方式就是登录和输入密码都是用 input 这个 tag name,然后取第一个就是用户名,取第二个就是密码
登录按钮就是 button 的 tag name,我想用 placeholder 和 “登录” 这个来定位元素怎么用,貌似上面允许的方法都不可行

共收到 1 条回复 时间 点赞

使用了 xpath,稍微好一点了,但是登录按钮这种还是没有特别好的办法,说下我的方法
driver.element('xpath', '//input[@placeholder="请输入用户名"]') 用来定位数据用户名参数
driver.element('xpath', '//div[@class="login-box"]').element('xpath', '//button') 定位登录页面,因为还有其他 button,所以这样基本不会定位错,也不怕开发频繁动前端代码

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册