请稍等 ...
×

采纳答案成功!

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

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

case执行的代码

from keywordselenium.actionMethod import ActionMethod
from util.exlcel_util import ExcelUtil

class KeywordCase:

    def run_main(self):
        self.actionmethod = ActionMethod()
        handle_excel = ExcelUtil(r'../config/keyword.xls')
        lines = handle_excel.get_lines()
        if lines:
            for i in range(1,lines):
                if_run = handle_excel.get_col_value(i,3)
                if if_run == 'yes':
                    method = handle_excel.get_col_value(i,4)
                    send_value = handle_excel.get_col_value(i,5)
                    handle_value = handle_excel.get_col_value(i,6)
                    self.run_method(method,send_value,handle_value)


    def run_method(self,method,send_value,handle_value):
        method_value = getattr(self.actionmethod,method)
        if send_value:
            method_value(send_value,handle_value)
        else:
            method_value(handle_value)

if __name__ == '__main__':
    run = KeywordCase()
    run.run_main()

执行方法的代码

from selenium import webdriver
from base.find_element import Findelement
from time import sleep

class ActionMethod:

    #打开浏览器
    def open_browser(self,browser):
        if browser == 'chrome':
            self.driver = webdriver.Chrome()
        elif browser == 'firefox':
            self.driver = webdriver.Firefox()
        else:
            self.driver = webdriver.Edge()

    #打开网页
    def get_url(self,url):
        self.driver.get(url)
        self.driver.maximize_window()

    #定位元素
    def get_element(self,key):
        findelement = Findelement(self.driver)
        element = findelement.get_element(key)
        return element

    #输入元素
    def element_send_keys(self,value,key):
        element = self.get_element(key)
        element.send_keys(value)

    #点击元素
    def click_element(self,key):
        self.get_element(key).click()

    #等待时间
    def wait_time(self):
        sleep(3)

    #关闭浏览器
    def close_browser(self):
        self.driver.close()

    #获取标题
    def get_tittle(self):
        tittle = self.driver.title
        return tittle

图片描述

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

1回答

Mushishi 2019-09-06 10:38:23

你调用关闭浏览器传递了参数

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信