UI自动化实现:接口参数定义为*loc函数,传多个参数时执行报错

 from time import sleep
 from selenium import  webdriver
 from selenium.webdriver.common.by import By

 #创建公共类传参,*loc代表支持传多个参数
  def get_element(driver,*loc):
     e =  driver.find_element(*loc)
     return e
 
 if __name__ == '__main__':
     driver = webdriver.Chrome()
     driver.get('http://www.baidu.com')
     driver.maximize_window()
     get_element(driver,(By.ID,'kw')).send_keys('测试')
     get_element(driver,(By.ID,'su')).click()
     sleep(3)

报错信息如下,重点关注前三行,提示信息中提到是value传参有问题

Traceback (most recent call last):
  File "E:/ui-demo/util.py", line 15, in 
    get_element(driver,(By.ID,'kw')).send_keys('测试')
  File "E:/ui-demo/util.py", line 8, in get_element
    e =  driver.find_element(*loc)
  File "E:\Program Files Work\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 859, in find_element
    'value': value})['value']
  File "E:\Program Files Work\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
    self.error_handler.check_response(response)
......

经排查发现是 *loc函数传参方式错误,修改14,15行的传参格式,去除()即可

14     get_element(driver,By.ID,'kw').send_keys('测试')
15     get_element(driver,By.ID,'su').click()

你可能感兴趣的:(UI自动化实现:接口参数定义为*loc函数,传多个参数时执行报错)