请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

TypeError: __init__() takes 1 positional argument but 2 were given

执行的时候,提示:TypeError: init() takes 1 positional argument but 2 were given

代码如下:
#coding=utf-8
import sys
sys.path.append(’/Users/helina/Desktop/hln/python/selenium/pythonProject4’)
from selenium import webdriver
import time
import random
from PIL import Image
#from ShowapiRequest import ShowapiRequest
from find_element import FindElement

class RegisterFunction(object):
def init(self,url):
self.driver = self.get_driver(url)
#获取driver并且打开URL
def get_driver(self,url):
driver = webdriver.Firefox()
driver.get(url)
driver.maximize_window()
return driver

#输入用户信息
def get_info(self,key,data):
    self.get_user_element(key).send_keys(date)

#定位用户信息,获取element
def get_user_element(self,key):
    find_element = FindElement(self.driver)
    user_element = find_element.get_element(key)
    return user_element

# 获取随机数
def get_range_user(self):
    user_info = ''.join(random.sample('123456789abcdefg', 6))
    return user_info

# 获取图片
def get_code_image(self,file_name):
    self.driver.save_screenshot(file_name)  # 截图,保存图片
    code_element = self.get_user_element("code_image")  # 查找验证码元素
    print(code_element.location)  # {'x':727,'y':527}
    left = code_element.location['x']
    top = code_element.location['y']
    right = int(code_element.size['width'] + left)
    height = int(code_element.size['height'] + top)
    im = Image.open(file_name)
    img = im.crop((left, top, right, height))
    # img = img.resize((right,height),Image.ANTIALIAS)
    img.save(file_name)

# 解析图片获取验证曲
def code_online(self,file_name):
    pass

def main(self):
    user_name_info = self.get_range_user()
    user_email = user_name_info + "@163.com"
    file_name = "/Users/helina/Desktop/imooc.png"
    code_text = self.code_online(file_name)
    self.get_info("user_email",user_email)
    self.get_info("user_name",user_name_info)
    self.get_info("password","111111")
    self.get_info("code_text",code_text)
    self.get_user_element("register_btn").click()
    time.sleep(10)
    self.driver.close()

if name == ‘main’:
register_function = RegisterFunction(“http://www.5itest.cn/register”)
register_function.main()

正在回答 回答被采纳积分+3

2回答

提问者 weixin_慕尼黑2157982 2022-01-28 10:23:33

下面是所有的报错信息:

Traceback (most recent call last):

  File "/Users/helina/Desktop/hln/python/selenium/pythonProject4/venv/register_function.py", line 69, in <module>

    register_function.main()

  File "/Users/helina/Desktop/hln/python/selenium/pythonProject4/venv/register_function.py", line 59, in main

    self.get_info("user_email",user_email)

  File "/Users/helina/Desktop/hln/python/selenium/pythonProject4/venv/register_function.py", line 23, in get_info

    self.get_user_element(key).send_keys(date)

  File "/Users/helina/Desktop/hln/python/selenium/pythonProject4/venv/register_function.py", line 27, in get_user_element

    find_element = FindElement(self.driver)

TypeError: __init__() takes 1 positional argument but 2 were given


0 回复 有任何疑惑可以回复我~
  • /register_function.py", line 27, in get_user_element 把你这个类发一下。应该是参数传递错误。你仔细看一下
    回复 有任何疑惑可以回复我~ 2022-01-28 13:46:55
Mushishi 2022-01-27 20:26:57

 init() takes 1 positional argument but 2 were given

你这个是参数传递个数问题。但是我看你RegisterFunction 不存在,你看看错误都发一下。是不是还有其他类得函数里面存在缺少

0 回复 有任何疑惑可以回复我~
  • 老师,已经把全部报错提示都复制上了,您帮忙看一下
    回复 有任何疑惑可以回复我~ 2022-01-29 14:45:54
  • Mushishi 回复 提问者 weixin_慕尼黑2157982 #2
    find_element = FindElement(self.driver)
    
    TypeError: __init__() takes 1 positional argument but 2 were given
     这个findElement 传递参数有问题
    回复 有任何疑惑可以回复我~ 2022-02-01 18:13:54
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信