Forum Discussion

Kate's avatar
Kate
Contributor
8 years ago

Unable to get attribute value

Here is a piece of my code:

 

inbox_mails = page.EvaluateXPath("//tr[contains(@id, 'sample_id')]")
  if not inbox_mails:
    Log.Error('Could not find emails')
  else:
    Log.Message('%s emails found' % str(len(inbox_mails)))
    mail_ids = [i.getAttribute("id").strip("sample_id") for i in inbox_mails]
 
 

My inbox_mails gets appropriate number of items in it.

However, my mail_ids stays empty...

 

What's wrong with it?

 

Thanks

6 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Hi,

     

    Can you show how initially looks the id attribute for tr element?

     

    • Kate's avatar
      Kate
      Contributor

      It looks like, let's say, 'sample_id1', 'sample_id2', 'sample_id3' and so on. I don't know the maximum id.

      Final purpose is to interact with tr with max number.

       

      My logic is as follows:

      1. Collect all tr elements with relevant ids (by partial id) to one list.

      2. Grab all full ids to another list, find maximum number (compare number parts).

      3. Interact with tr with maximum number from the first list based on index of 'maximum id' element in the second list.

       

       

      • baxatob's avatar
        baxatob
        Community Hero

        Syntactically you code looks correct. 

         

        What is your further code after extracting of mail_ids

         

        Note that mail_ids contains a collection of strings in your case.

        If you want to perform some comparison operation with them, you should convert strings to integers first.