繁体   English   中英

如何修复TypeError:getText()缺少1个必需的位置参数:python中的'self'?

[英]How to fix TypeError: getText() missing 1 required positional argument: 'self' in python?

**我在此 class 中调用 class 重用的方法 ** '''

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)

'''

这是在我创建方法的地方重用 class

    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)

您需要实例化 Reuse 并调用该 object 上的方法。

类似的东西:

@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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM