测试积点老人 发表于 2021-8-5 11:30:09

提示错误: TypeError: locator() takes 2 positional arguments but 3 were given


封装:
from selenium import webdriver
def brower(type_):
    try:
      driver = getattr(webdriver, type_)()
    except:
      driver = webdriver.Chrome()
    return driver
class web_ui:
    # driver = webserver.Chrome()
    # 构造函数
    def __init__(self, type_):
      self.driver = brower(type_)
    # 打开url
    def open(self, url):
      self.driver.get(url)
    # 元素定位
    def locator(self, value):
      return self.driver.find_element(value)
    # 点击
    def click_(self, name, value):
      self.locator(name, value).click()
    # 输入
    def send_(self, name, value, txt):
      self.locator(name, value).send_keys(txt)
    # 退出
    def quit_(self):
      self.driver.quit()
    # 等待
    def sleep_(self, value=10):
      self.driver.implicitly_wait(value)

调用:
from selenium1.web_ui import Web_ui
web = Web_ui('Firefox')
web.open('http://www.baidu.com')
web.send_('id', 'kw','python')
提示错误:
TypeError: locator() takes 2 positional arguments but 3 were given

海海豚 发表于 2021-8-6 10:32:40

https://blog.csdn.net/aigan8070/article/details/101573377   看下这个

qqq911 发表于 2021-8-6 10:33:12

多给了一个参数

bellas 发表于 2021-8-6 11:09:36

参考下这个链接
https://blog.csdn.net/aigan8070/article/details/101573377   看下这个
页: [1]
查看完整版本: 提示错误: TypeError: locator() takes 2 positional arguments but 3 were given