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