How to store the content/value of xpath?
14,047
Solution 1
Try storeText ( locator, variableName )
Then use it ${variableName}
Refer Selenium documentation for storeText
Solution 2
saga told you how to store that string, as you need to store only 145300, below code will help you
store | Displaying 1 to 30 of 145300 | string
store | 1 | delimiter
store | javascript{storedVars['string'].split('of')[storedVars['delimiter']]} | result
echo | ${result}
Author by
Jackie James
Updated on July 29, 2022Comments
-
Jackie James almost 2 years
Assume xpath as below:
xpath : //div[@id='cslGridViewPanelControl']/div/div[2]/div/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody/tr/td/div Last div element contains 'Displaying 1 to 30 of 145300'. I need to store 'Displaying 1 to 30 of 145300' in some variable by using selenium tool.
I tried
command target value store xpath variable1 echo ${variable1}
It displays as variable1: xpath. But i need variable1: 'Displaying 1 to 30 of 145300'. Can anyone help me please ?
-
Jackie James about 12 years@ Saga:Thank U, it works fine. Now i need to parse the text stored in this variable. If the text stored is 'Displaying 1 to 30 of 145300', i need to store only 145300 in another variable. how can i do it ?
-
sagaofsilence about 12 yearsRegex can help you. Displaying\\s+\\d+\\s+to\\s+\\d+\\s+of\\s+\\d+
-
Jackie James about 12 yearsI didn't get u. How can i put it ? Can u be bit clear, please ?
-
sagaofsilence about 12 yearsAssuming that Javascript is used: var str="Displaying 2 to 30 of 145300"; var num = str.split(" ").pop();