Re: [Wtr-general] How do you find a specific string in an HTML page?
Regular expressionliness is next to godliness. # This next line will set its_there to true if, in the html for the page, it sees # the string "customerID=" followed by any seventeen characters, and # (courtesy of the parens) will set $1 to whatever those seventeen # characters are. its_there = ie.html =~ /customerID=(.{17})/ # and if its_there is true, myvariable will get the value assigned to it if(its_there) myvariable = $1 end There may be a more elegant way to do it (say, by getting the inner_text of the link and parsing that), but the basic principle is that regular expressions are your friends. ---Michael B. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul CarvalhoSent: February 9, 2006 4:14 PMTo: wtr-general@rubyforge.orgSubject: [Wtr-general] How do you find a specific string in an HTML page? Hi there, I am trying to find a way to find a particular string in an HTML page and save it to a variable. It seems simple enough, but I can't find the commands to help me do it yet.Our Dot-Net app assigns Unique ID's to various objects within the system. For example, if you create a new Customer in an Order-Taking system, the new Customer is assigned a unique ID (let's call it "customerID"). When I look at the HTML page, I see that UID in various places. For example:(a) within a "div" tag (within a custom attribute unrecognised by Watir)(b) within an "a href" link (part of the URL - e.g. "http://www.../../ShowCustomer.aspx?mode=edit&customerID=1234asdf-5678hjlk")I know that I can use the contains_text() to look for text on the page. I can also use ie.frame("frameName").html.to_s to capture the contents of the frame. So how can I tell Watir to find the "customerID=" phrase and then capture the next [fixed-number] set of characters into a string variable?Thanks in advance.Paul. ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] How do you find a specific string in an HTML page?
I always like to use the _javascript_ objects. So one way is to be able to get the _javascript_ underlying object from the div reference in WATIR. Then when you get that just call the getAttribute() method on that object and pull out the attribute that you would like. Another way would be to use the XML Xpath against the DOM to pull the data that you want. I am not too familiar with this but I know it can be done. Sergio From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Carvalho Sent: Thursday, February 09, 2006 1:14 PM To: wtr-general@rubyforge.org Subject: [Wtr-general] How do you find a specific string in an HTML page? Hi there, I am trying to find a way to find a particular string in an HTML page and save it to a variable. It seems simple enough, but I can't find the commands to help me do it yet. Our Dot-Net app assigns Unique ID's to various objects within the system. For example, if you create a new Customer in an Order-Taking system, the new Customer is assigned a unique ID (let's call it "customerID"). When I look at the HTML page, I see that UID in various places. For example: (a) within a "div" tag (within a custom attribute unrecognised by Watir) (b) within an "a href" link (part of the URL - e.g. "http://www.../../ShowCustomer.aspx?mode=edit&customerID=1234asdf-5678hjlk") I know that I can use the contains_text() to look for text on the page. I can also use ie.frame("frameName").html.to_s to capture the contents of the frame. So how can I tell Watir to find the "customerID=" phrase and then capture the next [fixed-number] set of characters into a string variable? Thanks in advance. Paul. ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
[Wtr-general] How do you find a specific string in an HTML page?
Hi there, I am trying to find a way to find a particular string in an HTML page and save it to a variable. It seems simple enough, but I can't find the commands to help me do it yet. Our Dot-Net app assigns Unique ID's to various objects within the system. For example, if you create a new Customer in an Order-Taking system, the new Customer is assigned a unique ID (let's call it "customerID"). When I look at the HTML page, I see that UID in various places. For example: (a) within a "div" tag (within a custom attribute unrecognised by Watir) (b) within an "a href" link (part of the URL - e.g. "http://www.../../ShowCustomer.aspx?mode=edit&customerID=1234asdf-5678hjlk") I know that I can use the contains_text() to look for text on the page. I can also use ie.frame("frameName").html.to_s to capture the contents of the frame. So how can I tell Watir to find the "customerID=" phrase and then capture the next [fixed-number] set of characters into a string variable? Thanks in advance. Paul. ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general