Hi akila,
You can remove intermediate Find calls and add the search depth instead. For example:
Before:
IButton button = Driver.Find<IProcess>(new ProcessPattern(){
ProcessName = "S******"
}).Find<ITopLevelWindow>(new WindowPattern(){
WndClass = "Afx:00400000:b*"
}).Find<IWindow>(new WindowPattern(){
WndClass = "AfxMDIFrame100u"
}).Find<IWindow>(new WindowPattern(){
WndClass = "AfxMDIFrame100u"
}).Find<IWindow>(new WindowPattern(){
WndClass = "AfxFrameOrView100u",
Index = 2
}).Find<IWindow>(new WindowPattern(){
WndClass = "ATL:00534B90",
WndCaption = "A*** E****e"
}).Find<IWindow>(new WindowPattern(){
WndClass = "ATL:00534278"
}).Find<IWindow>(new WindowPattern(){
WndClass = "Shell Embedding"
}).Find<IWindow>(new WindowPattern(){
WndClass = "Shell DocObject View"
}).Find<IWebPage>(new WindowPattern(){
WndClass = "Internet Explorer_Server"
}).Find<IWebPage>(new WebPagePattern(){
URL = "file://***********************.htm*",
ObjectGroupIndex = 0
}).Find<IButton>(new WebElementPattern(){
ObjectType = "Button",
idStr = "p***********002"
}, 3);
After:
IButton button = Driver.Find<IProcess>(new ProcessPattern(){
ProcessName = "S******"
}).Find<ITopLevelWindow>(new WindowPattern(){
WndClass = "Afx:00400000:b*"
}, 4).Find<IWindow>(new WindowPattern(){
WndClass = "ATL:00534B90",
WndCaption = "A*** E****e"
}).Find<IWebPage>(new WebPagePattern(){
URL = "file://***********************.htm*"
}, 5).Find<IButton>(new WebElementPattern(){
ObjectType = "Button",
idStr = "p***********002"
}, 3);
You can also use variables to store objects that you are going to re-use in other search patterns:
IProcess myApp = Driver.Find<IProcess>(new ProcessPattern(){ ProcessName = "S******" });
IWebPage page = myApp.Find<ITopLevelWindow>(new WindowPattern(){
WndClass = "Afx:00400000:b*"
}, 4).Find<IWindow>(new WindowPattern(){
WndClass = "ATL:00534B90",
WndCaption = "A*** E****e"
}).Find<IWebPage>(new WebPagePattern(){
URL = "file://***********************.htm*"
}, 5);
IButton button = page.Find<IButton>(new WebElementPattern(){
ObjectType = "Button",
idStr = "p***********002"
}, 3);