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(原理详解)
本文探讨了在使用Selenium进行自动化测试时常见的四个问题及其解决方案,包括展开二级菜单、元素被掩盖、元素无法滚动到视图内以及常规点击方法失效的情况。文章提供了具体的代码示例和修改建议,帮助读者有效解决Selenium测试中遇到的难题。
636

被折叠的 条评论
为什么被折叠?



