cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
New Contributor

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 1
Community Hero

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

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.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================