Parsing Strings in Katalon – Split, Substring and Readlines
Once text has been read from the page, it’s time to do something with it. In many cases, only a portion of the text is needed. For example, you may need the first part of a text string, or the last part. An example text string would be: (1/26/2018 – DAY 19 OF 22) The first thing is to read in the entire string into a variable: importDate = WebUI.getText(findTestObject(‘Page_/Sales Dashboard/mtd_Sales_Dashboard_Import_Date’)) Since I want the text to the left of the hyphen, I can use that in my split command. The [0] at the end indicates I want text to the left. If I change it to [1] it would be text to the right. parsedDate = (importDate.split(‘ – ‘)[0]) – returns (1/26/2018 parsedDate = (importDate.split(‘ – ‘)[1]) – returns DAY 19 OF 22) From there I can manipulate the text further for my needs. It’s also possible to break the line at the hyphen and return the resulting two […]
Recent Comments