Answered

Substring command

How to start with last characters

0
5 comments
Avatar
Olena Mazikina

Hello team!

I need to cut the last four characters of my String. For this, I need to know the length of my String. Could you please help me with what kind of command I need to use to find the length because all the names of my files are changing. And with Substring, I can cut only the first characters.

0
Comment actions Permalink
Avatar
Rex Feizi

You can use the exclude characters of the get_web command. You need to use a regular expression that matches the last 4 characters of your string. Here is the RegEx ".{4}$". 

Below is the example where we do the following steps: 

1. Browse to https://www.subject-7.com

2. Read the string "Let coders code and testers test". Remove the last 4 characters 

3. Print the variable that should hold "Let coders code and testers". Last 4 characters ("Test") are removed. 

 

To run the example below do the following: 

 

1. Create a locator with key  subject7_home.h1.let_coders_code and XPath=(//div[@class='sqs-block-content']/h1)[1]

2. Create a new test case, switch to the advanced view where the command editor is. Paste the below lines and save the test case. 

 

WEB GOTO_URL "https://www.subject-7.com" HALT ON ERROR
WEB VALUE_GET RESULT_VARIABLE my_var SOURCE LOCATOR subject7_home.h1.let_coders_code XML_TYPE "{http://www.w3.org/1999/XSL/Transform}NODE" ATTRIBUTE "TEXT" EXCLUDECHARS ".{4}$" HALT ON ERROR
PRINT @my_var HALT ON ERROR

0
Comment actions Permalink
Avatar
Olena Mazikina

For some reason the command editor does not have an apply or save button, so every time I exit out of it the code does not save and it is not running at all.

0
Comment actions Permalink
Avatar
Payam Fard

Olena,

The version of your Subject7 instance is few releases old. We need to upgrade it to have access to the latest. We will plan an upgrade in the next couple of days.

Thanks.

0
Comment actions Permalink

Please sign in to leave a comment.