‘WebElement’ object has no attribute ‘sendKeys’

1.应广大市民反映,为减少人员集聚,自2020年2月24日(含)起,暂停“门店自取”口罩预约方式。

2.前期市民放弃预约各门店购买资格的口罩,将于2月23日在“门店自取”预约系统中全部投放,当天预约成功的市民可在2月25日(含)前到预约门店购买,逾期不再保留。

3.市民可继续通过“快递配送”方式自愿预约购买。自2月25日(含)起,“快递配送”预约系统开放时间,按照快递公司不同分为每天上午9:30和10:00两个时段。邮政、顺丰等量承担配送任务,市民可自行选择配送公司。

因为一个病毒导致很多事情都变的面目全非,口罩、消毒液都成了紧俏用品。为了能够买到口罩,就需要弥补手速过慢的问题。手速太慢了是抢不到口罩的,所以此时就需要自动提交数据。找到网址之后。很容易就可以定位到所有的输入框:



真题就是一排input,加两个select:

<div class="weui-cells vux-no-group-title"> 
<div class="vux-x-input weui-cell">
<div class="weui-cell__hd"><!----> <label for="vux-x-input-eknci" class="weui-label" style="width: 5.5em; text-align: right; margin-right: 2em;">姓名</label> <!----></div>
 
<div class="weui-cell__bd weui-cell__primary"><input id="vux-x-input-eknci" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="text" placeholder="必填" class="weui-input"/> <!----> <!----> <!----> <!----></div>
 
<div class="weui-cell__ft"><i class="weui-icon weui_icon_clear weui-icon-clear" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i> <!----> <i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" style="display: none;"></i>  <!----></div>
 
<div class="vux-toast">
<div class="weui-mask_transparent" style="display: none;"></div>
 
<div class="weui-toast weui-toast_text" style="width: auto; display: none;"><i class="weui-icon-success-no-circle weui-icon_toast" style="display: none;"></i> 
 
</div>
</div>
</div>
 
<div class="vux-x-input weui-cell">
<div class="weui-cell__hd"><!----> <label for="vux-x-input-ygnvd" class="weui-label" style="width: 5.5em; text-align: right; margin-right: 2em;">电话</label> <!----></div>
 
<div class="weui-cell__bd weui-cell__primary"><input id="vux-x-input-ygnvd" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="text" placeholder="必填" class="weui-input"/> <!----> <!----> <!----> <!----></div>
 
<div class="weui-cell__ft"><i class="weui-icon weui_icon_clear weui-icon-clear" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i> <!----> <i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" style="display: none;"></i>  <!----></div>
 
<div class="vux-toast">
<div class="weui-mask_transparent" style="display: none;"></div>
 
<div class="weui-toast weui-toast_text" style="width: auto; display: none;"><i class="weui-icon-success-no-circle weui-icon_toast" style="display: none;"></i> 
 
</div>
</div>
</div>
 
<div class="vux-x-input weui-cell">
<div class="weui-cell__hd"><!----> <label for="vux-x-input-lvlqu" class="weui-label" style="width: 5.5em; text-align: right; margin-right: 2em;">身份证号</label> <!----></div>
 
<div class="weui-cell__bd weui-cell__primary"><input id="vux-x-input-lvlqu" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="text" placeholder="必填" class="weui-input"/> <!----> <!----> <!----> <!----></div>
 
<div class="weui-cell__ft"><i class="weui-icon weui_icon_clear weui-icon-clear" style=""></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i> <!----> <i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" style="display: none;"></i>  <!----></div>
 
<div class="vux-toast">
<div class="weui-mask_transparent" style="display: none;"></div>
 
<div class="weui-toast weui-toast_text" style="width: auto; display: none;"><i class="weui-icon-success-no-circle weui-icon_toast" style="display: none;"></i> 
 
</div>
</div>
</div>
 
<div class="vux-selector weui-cell weui-cell_select weui-cell_select-after">
<div class="weui-cell__hd"><label for="vux-selector-eieoq" class="weui-label" style="width: 5.5em; text-align: right; margin-right: 2em;">地区</label></div>
 
<div class="weui-cell__bd"><select id="vux-selector-eieoq" class="weui-select" style=""><!----> <!----> <option value="市南区">市南区</option><option value="市北区">市北区</option><option value="李沧区">李沧区</option><option value="崂山区">崂山区</option><option value="青岛西海岸新区">青岛西海岸新区</option><option value="城阳区">城阳区</option><option value="即墨区">即墨区</option><option value="胶州市">胶州市</option><option value="平度市">平度市</option><option value="莱西市">莱西市</option></select></div>
</div>
 
<div class="vux-selector weui-cell weui-cell_select weui-cell_select-after">
<div class="weui-cell__hd"><label for="vux-selector-tq5q0" class="weui-label" style="width: 5.5em; text-align: right; margin-right: 2em;">街道</label></div>
 
<div class="weui-cell__bd"><select id="vux-selector-tq5q0" class="weui-select" style=""><!----> <!----> <option value="世园街道办事处">世园街道办事处</option><option value="楼山街道办事处">楼山街道办事处</option><option value="九水街道办事处">九水街道办事处</option><option value="湘潭路街道办事处">湘潭路街道办事处</option><option value="兴华路街道办事处">兴华路街道办事处</option><option value="振华路街道办事处">振华路街道办事处</option><option value="虎山路街道办事处">虎山路街道办事处</option><option value="兴城路街道办事处">兴城路街道办事处</option><option value="沧口街道办事处">沧口街道办事处</option><option value="李村街道办事处">李村街道办事处</option><option value="浮山路街道办事处">浮山路街道办事处</option></select></div>
</div>
 
<div class="weui-cell vux-x-textarea">
<div class="weui-cell__hd"><!----> <label class="weui-label" style="width: 5.5em; text-align: right; margin-right: 2em;">详细地址</label> <!----></div>
 
<div class="weui-cell__bd"><textarea autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" placeholder="必填" rows="3" cols="30" class="weui-textarea"></textarea> 
<div class="weui-textarea-counter" style="display: none;"><span>19</span>/
    </div>
</div>
</div>
 
<div class="vux-x-input weui-cell">
<div class="weui-cell__hd"><!----> <label for="vux-x-input-7t7o5" class="weui-label" style="width: 5.5em; text-align: right; margin-right: 2em;">验证码</label> <!----></div>
 
<div class="weui-cell__bd weui-cell__primary"><input id="vux-x-input-7t7o5" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" type="text" placeholder="必填" class="weui-input"/> <!----> <!----> <!----> <!----></div>
 
<div class="weui-cell__ft"><i class="weui-icon weui_icon_clear weui-icon-clear" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" title="" style="display: none;"></i> <!----> <i class="weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_success weui-icon-success" style="display: none;"></i> <i class="vux-input-icon weui-icon weui_icon_warn weui-icon-warn" style="display: none;"></i>  <!----></div>
 
<div class="vux-toast">
<div class="weui-mask_transparent" style="display: none;"></div>
 
<div class="weui-toast weui-toast_text" style="width: auto; display: none;"><i class="weui-icon-success-no-circle weui-icon_toast" style="display: none;"></i> 
 
</div>
</div>
</div>
 
<div class="shapeCode"><img src="./快递预约_files/saved_resource"/></div>
</div>

最开始的时候实用的id进行定位,但是后来发现这些id都是动态生成的,直接通过id定位就bug了。再次进入的时候会发现原来的input id都变了。于是改变思路直接遍历input进行处理,但是如果要多次填写信息就需要清空input。直接通过:

weuis[0].sendKeys(Keys.CONTROL, "a")
直接就bug了,可以通过ActionChains来实现:
ActionChains(driver).move_to_element(input).send_keys(Keys.DELETE)

另外,如果input.clear()并不是总能生效,可以通过下面的代码来删除内容:

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
def clear_input(input):
    ActionChains(driver).move_to_element(input).send_keys(Keys.CONTROL, "a")
    ActionChains(driver).move_to_element(input).send_keys(Keys.DELETE)
分享文章:

猜你喜欢:

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注