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(原理詳解)

發佈了53 篇原創文章 · 獲贊 15 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章