Xpath Newbie - How To use Beginning with and Ends with in example below

Hi Guys,

Just trying to do something a bit more complicated here. Basically, I have this line in the code

WebUI.click(findTestObject(‘Object Repository/Page_Site/span_617.95AUD’))

I would like to do is this -

WebUI.click(findTestObject(‘Object Repository/Page_Site/span_’ + “WildCard” + AUD))

Is this possible? Done some research into Xpath, and it still has me confused, I have read that it can’t be used with “findTestObject”. Is that still the case?

Ultimately, this is what I would like to do -

Int Total_Balance = WebUI.click(findTestObject(‘Object Repository/Page_Site/span_’ + “WildCard” + AUD))

Int Trade = Total_Balance / 5

WebUI.setText(findTestObject(‘Object Repository/Page_Site/input_in Australian dollars_amount’), Trade)

Xpath for Reference - //div[@id=‘globalWrapperPage’]/div[5]/div/div/div/button/span/span

Thanks In Advance!

You don’t seem to understand. The xpath is how the computer finds the element, but the above is just an object’s name. Absolutely no reason to have a wildcard in a name–just give it a generic name.
If you find the name in the Object Repository and double click on it, that will display the items that you are using to identify the element. Look for the xpath item. It’s here that you can use a parameter (your wildcard). Unfortunately, I don’t understand what part you would have as a parameter.


A click event does not return anything, so the above makes no sense. You will have to use another statement, like getText() or getAttribute(). First, you need to get the information from the element, which will be a String, after which, you can convert to an Integer (maybe a Double would be better). As an example:

def strMoney = WebUI.getText(findTestObject('Object Repository/Page_Site/span_AUD'))
def total_Balance = strMoney as Double

def trade = total_Balance / 5

WebUI.setText(findTestObject('Object Repository/Page_Site/input_in Australian dollars_amount'), trade.toString())
1 Like

Hi Grylion!

Thank you very much, you are correct, I didn’t understand how the Object Repository works.

Found it, removed references that were too specific to the initial capture.

Then ran the following -

def value = WebUI.getText(findTestObject(‘Object Repository/Page_Site/span_617.95AUD’)).replaceAll(“[$,]”,“” )

value = value.replaceAll(“[A-Z]”,“” )

def total_Balance = value as Double

def trade = total_Balance / 5

WebUI.click(findTestObject(‘Object Repository/Page_Site/button_Buy’))

WebUI.click(findTestObject(‘Object Repository/Page_Site/button_Market buy in dollars’))

WebUI.setText(findTestObject(‘Object Repository/Page_Site/input_in Australian dollars_amount’), trade.toString())

Works perfectly.


1 Like

Thank you Mike @grylion54 for your support! It’s great to see lots of users benefit from your help.