Forum Discussion

parthparikh051's avatar
parthparikh051
New Contributor
6 years ago

Python AttributeError: 'Nonetype@ object has no attribute 'SetFocus'

I have the below code snippet written in Python

filltext= page.FindChildByXPath('//Input[@Id="textbox1"]',True)
filltext.SetFocus()
filltext.Keys("abcd")

It is not able to SetFocus() OR Click() OR Keys() on this text box.

 

When i Tried to log the type of 

Log.Message(GetVarType(filltext))

It returns 0. Can someone please help me to resolve this error?

1 Reply

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > .FindChildByXPath()

    As per documentation:

    If the object is searched by XPath and is found, TestComplete tries to match the found object to the one from its objects tree. If the match succeeds, then TestComplete returns its wrapping object that contains all properties and methods added by TestComplete (SetFocus(), .Keys(), etc.).

    If the match fails, than native DOM object is returned. In this case test code can use only native properties/methods provided by DOM for this given object within given web browser.

    If search by XPath fails then (as described in the XPath documentation) null is returned.

     

    The above is one from a number of reasons why XPath is highly not recommended practice in TestComplete's world.

     

    So, the reason of your problem is simple: XPath failed to find the sought for object.

    Recommended correction that works in most of cases: replace .FindChildByXPath() with .FindChildEx() and provide long enough timeout value to guarantee that the sought for control is rendered on the screen.