执行的时候,提示: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()