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}
Share:
14,047
Jackie James
Author by

Jackie James

Updated on July 29, 2022

Comments

  • Jackie James
    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
    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
    sagaofsilence about 12 years
    Regex can help you. Displaying\\s+\\d+\\s+to\\s+\\d+\\s+of\\s+\\d+
  • Jackie James
    Jackie James about 12 years
    I didn't get u. How can i put it ? Can u be bit clear, please ?
  • sagaofsilence
    sagaofsilence about 12 years
    Assuming that Javascript is used: var str="Displaying 2 to 30 of 145300"; var num = str.split(" ").pop();