Forum Discussion

testfeast's avatar
testfeast
Occasional Contributor
9 months ago

Using Page Object as return type

Trying to write a function like:

def foo() -> Page:
 #does something
 return page

It returns a variable of type Page in TestComplete.

 

However, it gives me a runtime error: NameError: name 'Page' is not defined.

How should I change my code?

1 Reply

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You need to define a Type Alias first, e.g.

    Page = Sys.Browser().Page("https://www.w3schools.com/csS/css3_buttons.asp") # Type Alias
    
    def MyPage() -> Page:
        return Page
    
    def main():
        Sys.HighlightObject(MyPage())