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

How to extract the element from a barcode image

3 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nhan Ai
Top achievements
Rank 2
Nhan Ai asked on 22 Jan 2014, 08:51 PM
I want to use Extract element to record a order bar code number on a website.

The difficulty I ran into is that:
- There is no Attribute ID, class, or src distinction for this barcode (there are more than 1 bar codes on this website)

Can i by any chance use the table cell reference to acquire the number of that barcode?
If I can locate the certain cell, how can I get the link of the image, and extract only the digits out of it?



Thank you,
Nhan Ai

3 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 23 Jan 2014, 03:11 PM
Hello Nhan,

Thank you for contacting.

Let's assume you have an image with ID="id" (just for the example). Here is a sample code how you can achieve it. It gets only the numbers of the image source string via a regular expression.

HtmlImage myImg = ActiveBrowser.Find.ById<HtmlImage>("id");
string src = myImg.Src;
Match m = Regex.Match(src, @"\d+");
Log.WriteLine(m.ToString());

Note that you should add assembly reference to System.Text.RegularExpressions.

Here is a demonstration video.

Let me know if this helps.

Regards,
Boyan Boev
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Nhan Ai
Top achievements
Rank 2
answered on 27 Jan 2014, 08:36 PM
Thank you for your response.

However, I cannot get anywhere close to your suggested method to get the partial string from the src, since the webpage I am trying to get the barcode element from does not have an ID for its image.

0
Boyan Boev
Telerik team
answered on 30 Jan 2014, 04:04 PM
Hello Nhan,

Yes, that was only an example. In your case you should find some unique combination of find rules to find that particular cell.

As I can see from your screen shot there is nothing static or unique. I assume that order date and total are every time different so you cannot use them to find the specific cell, Am I right?

An option is to use XPath. We are not recommend it in the most cases, but in your case it seems that this is the only option.

If you want to find the very first IMG in that table you can use this code:

HtmlTable myTable = ActiveBrowser.Find.ByExpression<HtmlTable>("class=confirmation");
HtmlImage myImg = myTable.Find.ByExpression<HtmlImage>("tagname=img");
string src = myImg.Src;
Match m = Regex.Match(src, @"\d+");
Log.WriteLine(m.ToString());

Is it possible to grant us a direct access to that application. I can try to find another solution for you.

Hope to hear from you soon.


Regards,
Boyan Boev
Telerik
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Nhan Ai
Top achievements
Rank 2
Answers by
Boyan Boev
Telerik team
Nhan Ai
Top achievements
Rank 2
Share this question
or