首页 > 解决方案 > 如何修复TypeError:getText()缺少1个必需的位置参数:python中的'self'?

问题描述

**我在这个类中调用类重用方法**'''

from behave import *
from Functions_Orange.reuse import Reuse
from Resources import Locator

class Orange:


 @given('Navigate to organeHRM')
 def Navigate_loginPage(context):
    print("Testing======Test \n")
    print(Locator.Locator_UserName)
    Reuse.sendText(Locator=Locator.Locator_UserName,Text=Locator.UserName)
    Reuse.sendText(Locator=Locator.Locator_passWord,Text=Locator.Password)

'''

这是我创建方法的重用类

    from Resources.Driver import *
class Reuse(Driver):
    y = Driver()
    y.intialise()
    def markElement(self,Locator):
      self.intialise().find_element_by_xpath(Locator)
    def click(self,Locator):
      self.intialise().find_element_by_xpath(Locator).click()
    def getText(self,Locator):
       self.intialise().find_element_by_xpath(Locator)
       return self.y.__getattribute__("text")
    def sendText(self,Locator,Text):
        self.intialise().find_element_by_xpath(Locator).send_keys(Text)

标签: pythonselenium

解决方案


您需要实例化 Reuse 并调用该对象的方法。

类似的东西:

@given('Navigate to organeHRM')
def Navigate_loginPage(context):
    print("Testing======Test \n")
    print(Locator.Locator_UserName)
    r = Reuse()
    r.sendText(Locator=Locator.Locator_UserName,Text=Locator.UserName)
    r.sendText(Locator=Locator.Locator_passWord,Text=Locator.Password)

推荐阅读