I want to store this H1 Description into a keyword so i can use the value of this keyword any where to type
have anyone store H1 description refer the screenshot attached
I want to store this H1 Description into a keyword so i can use the value of this keyword any where to type
have anyone store H1 description refer the screenshot attached
use the following
attribute = WebUI.getText(findTestObject(‘your test object’))
if the abvoe didnt work try this
attribute = WebUI.getAttribute(findTestObject(‘Your test object’), ‘innertext’)
You need to use storeText
and reference the variable with ${Recent_Sample}
For example:
Command | Target | Value
open | http://forum.katalon.com/t/want-to-store-h1-description-in-a-keyword/18974
storeText | xpath=(.//*[normalize-space(text()) and normalize-space(.)='Free Download'])[1]/following::a[8] | Recent_Sample
echo | ${Recent_Sample}
The echo
command will display the value in the log tab.
Hi Mark
I tried this and it picked up the description of the H1 tag
Now I have another problem ; storing this description in one keyword i.e $ {Recent_Sample} and passing this value is typing the entire text.
lets say the Description of H1 tag is
so once I have the this text stored - any way i can split it or alter it any command to do that
Thanks Heaps
Cheers
Rakii
sampleText.split(’:’)
Add these lines after those in my first response
storeText | xpath=(.//*[normalize-space(text()) and normalize-space(.)='Rakii8516'])[2]/following::h1[1] | h1Text |
storeEval | storedVars['h1Text'].split(' ')[1] | secondValue |
echo | ${secondValue} | |
Take note of the character used to split the string. In this example I’m using a space (' ')
, but you could use a colon (':')
, although the stored value would then contain a space at the start ' NBR123'
, assuming your title is always in the same format as in your example.
As a bit of explanation for anyone that wants to know what’s going on
storeEval
evaluates a JavaScript snippet.
The JavaScript function split()
creates an array using the character provided to delimit the elements.
JavaScript arrays are zero-based which is why we use the index of 1
to get the second element.
Great Help Mark
This is Done Thanks Heaps
Hi Mark
I have been trying your solution on this one as well but not getting it right
I have this copied text NZL2019/MAF/200 - which gets autogenerated - i want to only store last number after / which in this case is 200
please refer to the screenshot
thanks
In this case you would need to split the string on the ‘/’ character. And because the string would be split into three parts, you want the third index ‘2’
Something like
storeText | xpath=(.//*[normalize-space(text()) and normalize-space(.)='Rakii8516'])[2]/following::h1[1] | h1Text |
storeEval | storedVars['h1Text'].split('/')[2] | secondValue |
echo | ${secondValue} | |
Thanks Mark- it went straight through into it
passed
Thanks Heaps :)