0

I am trying to capture a piece of text from a website which keeps changing. It looks like :

Order ID : XXIO-123344-3456

The prefix is constant but the numbers will always change. I want to capture this number and store it. I have tried storeTextPresent with regex pattern regexp:Email.*@.*com. It does return me a True but it does not return me the value. Of course storeTextPresent is supposed to only return True or False. So now how can I capture the exact value?

Here's a screen shot of the part of the webpage. Can't show the whole page, so sorry.

enter image description here

So any ideas guys?

I export these test after recording into python remote control. So python specific code is more welcome.

Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
Arindam Roychowdhury
  • 5,927
  • 5
  • 55
  • 63
  • Can you show the code of what you actually tried and did not work? – Coral Doe Oct 17 '12 at 07:29
  • I have no code.....Consider you visit a web page . You launch selenium IDE . Start recording . You right click on the page text you want and select "storeTextPresent" . Thats what i was trying to do . Ok just try to capture the text "viewed 8 times" on this very page . You can see it on the right hand top corner . You want to capture "8 times" . So how do you do it? – Arindam Roychowdhury Oct 17 '12 at 07:34

4 Answers4

1

assertText command with the regular expression regexp:^XXIO-.+ would resolve the issue. Try this in conjunction with the element id you need to verify.

Adrian Heine
  • 4,051
  • 2
  • 30
  • 43
ssebastian
  • 19
  • 2
  • 1
    This won't give the desired result as it will return a boolean, not the actual text that arindam is looking for. – Luke Mills Oct 17 '12 at 23:17
0

Just had a look in the manual. I found the storeText command under Store Commands and Selenium Variables. My guess is that if you use storeText instead of storeTextPresent.

Also, instead of trying to find the text using a regex pattern, you could try using an xpath, DOM, or CSS locator.

Luke Mills
  • 1,616
  • 1
  • 11
  • 18
0

Thanks for the idea but i could'nt find a locater for the text. This is the code i captured using firebug .

<div class="chkOutBox">
<h2 id="tnq" class="marb10">Order Details</h2>
<div class="ordRevAddressArea">
<div class="ordRevDelSlotArea">
<div class="clear"></div>
<div class="bFont">Order ID:&nbsp; BBO-72262-171012</div>
<div class="scartPgHdr">
<h3 class="catHdr">Fruits &amp; Vegetables</h3>

Here we are capturing the id number (Line 6)......May be someone can tell me how to figure out a possible locater for this from the above code ....By the way I solved my problem by capturing the URL of the page which had the order ID.I used a regex to seperate out the order id and thats it.......Its only a temporary solution.......

Arindam Roychowdhury
  • 5,927
  • 5
  • 55
  • 63
  • You could even use a CSS locator. It is difficult to say what's best, because the html markup doen't convey much semantic meaning. The css classes look like they are based on visual style rather than semantic meaning. You could try `#tnq .bFont`. Better would be to add use semantic class names. Also, may I suggest that instead of adding extra information as an answer, you should edit your original question and add this information there. – Luke Mills Oct 17 '12 at 23:15
0

Python Code.

def get_order_id(driver):
    """ Gets the order id, given an Order Details page. """
    try:
        bFonts = driver.find_element_by_class_name("bFont")
        for element in bFonts:
            if "Order ID" in element.text:
                return element.text.split()[-1]
    except NoSuchElementException:
        return None

This assumes that the class name, bFont never changes. If it does, you can rewrite it to search over the div tag. It also assumes that "Order ID" will be found.

kreativitea
  • 1,741
  • 12
  • 14