一,在做自動化測試時候,顯示等待封裝一下定位元素的方法:
def find_element(self, *loc): try: WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(*loc)) return self.driver.find_element(*loc) except Exception as e: raise e
二、腳本執行提示:
意思就是,傳入了三個參數,但是只有兩個位置;
*loc 代表的是有三個參數:self,xpath和路徑地址
login_password_loc = (By.XPATH, "//input[@type='password']")
*parameter是用來接受任意多個參數並將其放在一個元組中;
所以,函數在調用多個參數時,在列表、元組、集合、字典及其他可迭代對象作為實參,並在前面加 *
如 *(1,2,3)解釋器將自動進行解包然后傳遞給多個單變量參數(參數個數要對應相等)
修改為:
def find_element(self, *loc): try: WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located(loc)) return self.driver.find_element(*loc) except Exception as e: raise e
解決問題。