python+selenium自动化测试-17解决.click()无法点击的问题(多情况分析)

1、.click()的替代方法
使用.click()无法展开二级菜单,遇到这个问题的时候,不妨可以试试模拟键盘的操作,用.send_keys(Keys.ENTER)可以解决这个问题。

from selenium.webdriver.common.keys import Keys

def type_openGoodList(self):
    try:
    	sleep(2)
		self.find_element(*self.taskMan6_loc).send_keys(Keys.ENTER)  # 展开二级菜单
        self.find_element(*self.goodList_loc).click()  #
    except BaseException as msg:
        print(msg)

2、该元素被同层元素掩盖了,无法被点击
在这里插入图片描述

#代码
lbl_loc = (By.CLASS_NAME, "lbl")
self.find_element(*self.lbl_loc).click()

#提示信息
Message: Element <span class="lbl"> is not clickable at point (991,233) because another element <input class="ace add-btn" name="userId" type="radio"> obscures it

解决方案:定位input元素,而不是span元素

3、提示“could not be scrolled into view”
在这里插入图片描述

userId_loc = (By.NAME,"userId")
self.find_element(*self.userId_loc).click()

Message: Element <input id="userId" name="userId" type="hidden"> could not be scrolled into view

解决方案:对input元素用Xpath定位

4、用以上方法还是不可以,请注意检查:(1)是不是网络差或者服务器响应缓慢导致元素加载不完全的情况(2)是否定位错误

【推荐】python+selenium自动化测试-16自动化测试模型
【推荐】python+selenium自动化测试-22python单元测试框架unittest(原理详解)

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值