51Testing软件测试论坛

标题: 提示错误: TypeError: locator() takes 2 positional arguments but 3 were given [打印本页]

作者: 测试积点老人    时间: 2021-8-5 11:30
标题: 提示错误: TypeError: locator() takes 2 positional arguments but 3 were given

  1. 封装:
  2. from selenium import webdriver
  3. def brower(type_):
  4.     try:
  5.         driver = getattr(webdriver, type_)()
  6.     except:
  7.         driver = webdriver.Chrome()
  8.     return driver
  9. class web_ui:
  10.     # driver = webserver.Chrome()
  11.     # 构造函数
  12.     def __init__(self, type_):
  13.         self.driver = brower(type_)
  14.     # 打开url
  15.     def open(self, url):
  16.         self.driver.get(url)
  17.     # 元素定位
  18.     def locator(self, value):
  19.         return self.driver.find_element(value)
  20.     # 点击
  21.     def click_(self, name, value):
  22.         self.locator(name, value).click()
  23.     # 输入
  24.     def send_(self, name, value, txt):
  25.         self.locator(name, value).send_keys(txt)
  26.     # 退出
  27.     def quit_(self):
  28.         self.driver.quit()
  29.     # 等待
  30.     def sleep_(self, value=10):
  31.         self.driver.implicitly_wait(value)

  32. 调用:
  33. from selenium1.web_ui import Web_ui
  34. web = Web_ui('Firefox')
  35. web.open('http://www.baidu.com')
  36. web.send_('id', 'kw','python')
  37. 提示错误:
  38. TypeError: locator() takes 2 positional arguments but 3 were given
复制代码



作者: 海海豚    时间: 2021-8-6 10:32
https://blog.csdn.net/aigan8070/article/details/101573377   看下这个
作者: qqq911    时间: 2021-8-6 10:33
多给了一个参数
作者: bellas    时间: 2021-8-6 11:09
参考下这个链接
https://blog.csdn.net/aigan8070/article/details/101573377   看下这个




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2