
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I'm testing an application where I am supposed to input an organization into a combo box. Once I click to another field, the system will then apply this logic: If the organization I entered does not exist in the application's database, a popup window will ask if I want to save it. If the organization was already present in the DB, no popup window displays.
My .NET script behaves correctly when I enter a new organization and click away; the popup opens and the script clicks 'Yes' in that window. But whenever the organization is already in the system, I get the playback error "XPath expression '@caption='New organization'' is invalid."
Can anybody determine what is wrong with my syntax for the If statement, or suggest a better alternative? I thought the script would begin at the next line after "End If" if the object doesn't exist.
Here are the relevant areas of the script:
Imports SilkTest.Ntf.Swt
Public Module Main
Dim _desktop As Desktop = Agent.Desktop
Public Sub Main()
With _desktop.Shell("@caption='Add Record'")
.ComboBox("[1]").TypeKeys("<OrganizationName>")
.TextField("[2]").Click
If .Shell("@caption='New organization'").Exists Then
With .Shell("@caption='New organization'")
.SetActive()
.PushButton("@caption='Yes'").Select()
End With
End If
.PushToolItem("@caption='Save and Close'").Select()
End With
End Sub
End Module
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
You might try searching for the popup window by calling Exists() off of its parent window:
If _desktop.Exists("//Shell[@caption='Add Record']") Then ' This code will execute when the popup window exists Else ' This code will execute when the popup window does not exist End If
Andy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
It seems that you are missing the square brackets in your locators. Can you try the below:
If .Shell("[@caption='New organization']").Exists Then
With .Shell("[@caption='New organization']")
.SetActive()
.PushButton("[@caption='Yes']").Select()
End With
End If
.PushToolItem("[@caption='Save and Close']").Select()
UFT | UFT Mobile | Silk Test
Micro Focus

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
What is full xpath locator for the .Shell("@caption='New organization'")?
UFT | UFT Mobile | Silk Test
Micro Focus

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
With _desktop.Shell("/Shell[@caption='Add Record']")
.ComboBox("[1]").TypeKeys("<OrganizationName>")
.TextField("[2]").Click
If .Shell("//Shell[@caption='Add Record']").Exists Then
With .Shell("/Shell[@caption='Add Record']")
.SetActive()
.PushButton("//PushButton[@caption='Yes']").Select()
End With
End If
.PushToolItem("[//PushToolItem[@caption='Save and Close']").Select()
End With
UFT | UFT Mobile | Silk Test
Micro Focus

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
You might try searching for the popup window by calling Exists() off of its parent window:
If _desktop.Exists("//Shell[@caption='Add Record']") Then ' This code will execute when the popup window exists Else ' This code will execute when the popup window does not exist End If
Andy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
If _desktop.Exists("//Shell[@caption='New organization']") Then
.PushButton("[@caption='Yes']").Select()
Else
.PushToolItem("[//PushToolItem[@caption='Save and Close']").Select()
End If
If _desktop.Exists("//Shell[@caption='New organization']") Then
.PushButton("[@caption='Yes']").Select()
End If
.PushToolItem("[//PushToolItem[@caption='Save and Close']").Select()