Hi all, i doing an automation testing using katalon. I need to know how to extract ONLY NUMBER from a string. For instance i wanted to extract ‘1421’ from “Application number: 1421” from the above page. The application number changes for every single testing.
Since it is a string and “Application Number:” is constant, you can try using subtring(starting char, ending char) or replaceAll("[^0-9.]", “”)
Something like this:
string extractInt = WebUI.getText(findTestObject(“your_Test_object”)).substring(20, 24)
string extractInt = WebUI.getText(findTestObject(“your_Test_object”)).replaceAll("[^0-9.]", “”)
Hope that helps. . .
I use copy your line, But not workiing,
string extractInt = WebUI.getText(findTestObject(‘myobject’)).substring(20, 24)
May I see your code?
It says no signature of method… did you include the “WebUI”??
string extractInt = WebUI.getText(findTestObject(‘Mportal/Page_AEON Credit Service (Asia)/p_Application Number 1421’)).substring(20, 24)
I replicated your error…
make the first letter of string a capital one like this: String
Katalon doesnt recognize “string” with a small “s”
Try it. . . .
and BTW as you can see in your error logs, you can see the “values: ” means it successfully eliminates the letters in your string.
you can also try to use the .replaceAll("[^0-9.]"), just in case the application number exceeds to 4 digits. . .
Sorry if I wrongly typed “string” earlier in my code. . . .
Hope that it works now on your side . . .
Bro, you’re amazing!!! It’s working like a charm!
Hi, similar scenario but this time i want to extract number from stings in .JSP page. (Which dont have objects!!). I tried use your previous code but failed. I just want get 4 DIGIT NUMBERs FROM the “TRANSACTION ID”. How can i do this??
What do you mean by this?
Could you send here the source of the page?
i meant the (Object Repository). Normally when doing web recording we capture the object by GetObject right? But this page cant able capture anything. Thats why i said, “it dont have objects”.
Below is the page source.
------------------------ Getting Parameter for merchant return page using method POST ---------------------- <br>
<br>AMOUNT = 30.00<br>
<br>AUTH_DATE = <br>
<br>AUTH_ID = <br>
<br>CAPTURE_DATE = <br>
<br>CUSTOMER_ID = Cust001<br>
<br>FR_LEVEL = -1<br>
<br>FR_SCORE = -1.0<br>
<br>MERCHANT_TRANID = <br>
<br>RESPONSE_CODE = 1005<br>
<br>RESPONSE_DESC = Invalid MERCHANT_ACC_NO&
#x21; & #xd;& #xa; Unable to find merchant with provided MERCHANT_ACC_NO.<br>
<br>TRANSACTION_ID = <br>
<br>TRAN_DATE = <br>
<br>TXN_STATUS = <br>
<br>SECURE_SIGNATURE = c09d1215df1789f962dbff9bc0fa6fd2cbd7f4e9b6cde5fa197548997dc1da110f9c44bc53665f4ed2455a0c03004c66e705fb07dc08d18e6c6411df7388c90f<br>
--------------- End of Getting Parameters --------------------
Moreover, when inspect the page, there is no Xpath, element & what so ever.
Actually, based on this link:
On the down most part of the page, you can follow the pattern there.
Like creating your own xpath:
make that your object locator
Try it. . .
Tried but failed. Where did it went wrong?
String extractInt = WebUI.getText(findTestObject(‘pay_win_auth_2/Transaction_id’)) .substring(15, 18)
Sorry late response… Quite busy on my work.
You can try this approach:
using Katalon Studio, I want to find elements by class. I tried to use the following script:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
Try to explore and play with it, do some refactoring something like:
import org.openqa.selenium.WebDriver as WebDriver
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = driver.findElements(By.tagName("<br>"))
I have a feeling that since it doesn’t have any objects, TagName is your key.
Hope that helps. . .
Its works!!! Thank you again brother!!!
Oh, very nice! you’re welcome… Glad I helped.