This is a migrated thread and some comments may be shown as answers.

Extract from HTML

20 Answers 420 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nicolas
Top achievements
Rank 1
Nicolas asked on 23 Dec 2010, 04:03 PM
hello,
I'd like to know how to extract element of an HTML page using Telerik, and how to put it in a db or excel file?
Regards
samir

20 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 23 Dec 2010, 05:46 PM
Hi Nicolas,
   you can access an extracted value from a coded step in the same way you access data in a Data-driven test:
((string)(System.Convert.ChangeType(Data["MyVariableToAccess"], typeof(string))));

However, there's a special method for using extracted variable that makes your life easier.

For example you have an extraction step that looks like this:
Extract "TextContent" on 'RadianceLink' into DataBindVariable $(RadianceLink)

Now you can access this extracted variable from a coded step like this:
String toBeStoredInExcel = (String ) GetExtractedValue("RadianceLink");
Now, the string toBeStoredInExcel contains your extracted value and you can store that in an Excel or any other external data storage. There's lot of tutorials on working with Excel you should have no trouble finding via an Internet search..

I hope this helps - let me know if you need more help!

All the best,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 28 Dec 2010, 11:24 AM
Hello,
my broblem what I am trying to determine how to find the parent of the div element in the page HTML from the id of the element back into the html page
as shown in this example in this attached screenshot
:

0
Cody
Telerik team
answered on 28 Dec 2010, 05:31 PM
Hi Nicolas,

I am not 100% certain I understand the problem you are trying to solve. It appears from your description and the screen shot that given the <a> element, you want to find the <div> element that has an id of "entry_1". Is that correct?

Is this ID unique to the entire webpage, and is it constant i.e. you will always want to find this specific ID? We can do that with a very simple find like this:

ActiveBrowser.Find.ByExpression<HtmlDiv>("id=entry_1");

This one line of code will search the current browser window and will return the first <div> element that has an id of "entry_1". If this doesn't meet your needs (perhaps the ID is a variable?) then please clarify the problem for us.

Greetings,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 29 Dec 2010, 10:51 AM
Hello,
Thank you firt for your reeply
No, this identification on page is not unique , there are several entry, my goal is to identify the correct element to extract the element by subscriber that is in the url href to find the parent div, and extract the id later
Kind Regards
0
Accepted
Cody
Telerik team
answered on 29 Dec 2010, 05:17 PM
Hi Nicolas,

Ok, so if you already have the <a> element contained in the variable "myAnch" you can use code like this to get to the 4th parent, which we'll assume is the <div> you want according to your screenshot.

HtmlDiv myDiv = myAnch.BaseElement.Parent.Parent.Parent.Parent.As<HtmlDiv>();

Does that get you what you need?

To extract the value of the id attribute from myDiv you'll need to use code like this:

string id;
foreach (iAttribute attr in myDiv.Attributes)
{
    if (attr.Name.Equals("id"))
    {
        id = attr.Value;
        break;
    }
}

All the best,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 30 Dec 2010, 11:59 AM
Thanks!
Now, this id I got, can I use it as part of an element locator for future steps?
Ie, can I data bind in my find logic something like id=[THE ID VARIABLE I FOUND],|,TagName=span,class=c75l entryStreet ?

One way might have been by adding an empty column in my data and fill it in the coded step, like data["entryId"] = id, but it's readonly.
Is there any other way?
0
Cody
Telerik team
answered on 03 Jan 2011, 07:19 PM
Hello Nicolas,

The Data object is a read only object, however you can use the SetExtractedValue function like this:

SetExtractedValue("extractedID", id);

This will add the variable "extractedID" to the Data object allowing you to reference it later via data binding.

Kind regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 06 Jan 2011, 11:56 AM
Great! That's exactly what we needed.
We just discovered the online API reference so we'll bug you with less questions from now on ;).
0
Nicolas
Top achievements
Rank 1
answered on 06 Jan 2011, 03:31 PM
Hello ;
I'd like to know how we can make a databinding on the locator
(if you want to add for example a step''locate In The Dom") in order to relate cetain elements of the html page and look at the db
Thank you !!
0
Accepted
Cody
Telerik team
answered on 06 Jan 2011, 09:31 PM
Hello Nicolas,

I'm afraid this can only be accomplished in code. Currently we don't support data binding of the elements that you see in our Elements Explorer, which is what standard (non-coded) test steps reference.

To perform this type of data binding in code you can use a coded step such as this:

HtmlImage img = ActiveBrowser.Find.ByExpression<HtmlImage>((String)Data["Expr1"], (String)Data["Expr2"]);

Unfortunately this also means that once you find the element you want to interact with, you can only do so in code. The found element cannot be used by a standard step.


Kind regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 07 Jan 2011, 06:15 PM
Hello Cody;
Thank you first for your reply
Wouldn'it be easier to modify the Locator of already declared elements? For example, let'say that I found the value entry_2 using the steps you mentioned, and I want to modify element AddressComplement which exists in the Elements Explorer and is used later by non-coded steps. Could I just modify its locator to replace all hard-coded "entry_1" with "entry_2"? In this case I have only one step in code and the other stay in a format that can be understood and modified by our quality expert.
0
Cody
Telerik team
answered on 07 Jan 2011, 11:23 PM
Hello Nicolas,

Just to make sure we're talking about the same objects, by "Locator" I believe you mean the Find Expression we have attached to each element that appears in Elements Explorer. In case you aren't aware, the Find Expression can be edited from Elements Explorer. Just right click on an element displayed in the pane, select Edit Element and the Find Expression Builder dialog will open allowing you to modify it. However this modification is only at design time, not run time.

You asked if these could be data bound... i.e. driven from data from some data source at run time. If the Find Expression attached to each element were exposed to coded methods, then you could and you could modify them as you just proposed. Unfortunately the Find Expression is buried within the element object and is not exposed to the public for either reading or writing by code.

The bottom line is that as far as test execution goes the elements Find Expression's (or Locator's) is cast in stone. It cannot be changed under any condition. Putting together your own Find Expressions in code as I previously showed you is the only alternative at this point in time.

You are not the first person to ask how to do this. We have a feature request already logged in our system to add the ability to data bind the definition (Find Expression) for how elements are found on web pages.

Kind regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 17 Jan 2011, 12:18 PM
Hello,
thank you for your reply, It helped me enormously
I also want to know how if I just rework in normal mode, after making some steps in code, and return to the page and make auther steps (without bcode)
Kind regards,
Nicolas
0
Nicolas
Top achievements
Rank 1
answered on 17 Jan 2011, 04:42 PM
I have also develop a test that includes steps of code, the problem that when I run my test normally it works well, but when I execute it with the  option "execute Without debuging", its not working, what's the solution for this?
thanks
0
Cody
Telerik team
answered on 18 Jan 2011, 04:27 AM
Hello Nicolas,

Regarding your very last post, obviously running without debugging should work exactly the same as with the debugger. It is the same execution engine just running without the debugging features enabled.

Without additional information on what the error is I cannot possibly offer a solution. The next time you get the error please export the test results to a .zip file and send them to me for analysis. Then I can assist with troubleshooting this problem.

Regarding your previous post, I don't really understand the question. It's as though it is cut off mid sentence "I also want to know how if I just rework in normal mode, after making some steps in code, and return tothe page and make auther steps (without bcode)". Can you reiterate what you're trying to ask?

Regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 19 Jan 2011, 01:01 PM
Hello
I put two files log attached ( with or without debug
), there is a big difference between these two files
The seconde question is  how I can add steps (without code) after a step test coded?
Thanks
0
Cody
Telerik team
answered on 21 Jan 2011, 10:42 PM
Hi Nicolas,

The log shows the test is failing inside your coded steps. I need to see this code before I can further diagnose this problem. Please put the test (the .aii, .resx and .cs) files into a .zip and attach it to your response please.

Kind regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 27 Jan 2011, 11:59 AM
Hello Stoish,
the solution given  passes for all cases, even if  CONTENT is different than NOARCHIVE
and I don't receive error message, so I don't know if the code works correctly or not?
Regards
0
Cody
Telerik team
answered on 28 Jan 2011, 10:31 PM
Hi Nicolas,

I think your response was meant for your other thread, not this one. I will respond on that thread.

Regards,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Nicolas
Top achievements
Rank 1
answered on 31 Jan 2011, 10:20 AM
Hello Cody ;
thank you for your reply it helped me enormously
 
Regards,
Nicolas
Tags
General Discussions
Asked by
Nicolas
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Nicolas
Top achievements
Rank 1
Cody
Telerik team
Share this question
or