11 years ago
extract text from web page and assign it to a variable
Hi there, I need to use TC to extract text from a web page control and store it in a variable, so that I can check for that same text elsewhere in the test. I don't know if this procedure has a name t...
- Most of my tests are written in VBScript so I may not be the best to answer this question for you, but let me give you some suggestions from my experience. Maybe that will get you going in the right direction.
I'll assume that if you can pull this information from the page (table cell) using Selenium that you know the tabel cell object that you're trying to pull from.
For Keyword tests try this:
1. Bring up the page on the 'AUT' (Application Under Test).
2. Select the 'Set Variable Value' from the 'Statements' operations.
3. Select the variable that you want to save the value in and click 'Next'.
4. Select 'Onscreen Object' and click on the '...' box on the right of the 'Value' text area.
5. Select the table cell object using one of the ways in the 'Select Object' dialog.
That should get you down the road on Keyword tests. Now I'll give you an example of what I would do using VBScript.
1. Start by setting the object varible to the table cell the value is in. This is an object that is in your Name Mapping. In VBScript you have to use Set to assign an object to a variable.
Set objToGetValueFrom = Aliases.browser.page.panelContent.table.cell
2. Assign the table cell value to a variable. In VBScript I use GetAttribute and then use the attribute name, in this example 'innerText', to tell it which attribute to get. This is where using your developer tools will help you to find the right attribute that you want to pull from the object. Other attributes could be 'outerText', 'isEnabled', 'bgColor', 'href', etc.
strValue = objToGetValueFrom.GetAttribute("innerText", text)
The strValue variable should now contain the value of the attribute innerText of the objToGetValueFrom object.
Obviously if you're using another language for scripting this will look a little different, but I hope this gets you a little bit further down the road. Let me know if this doesn't make sense.