dcsimg
Results 1 to 9 of 9

Thread: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using vba

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    4

    Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using vba

    I have a few html files and those are the results of automation results having 'Pass' or 'Fail' status. These html files are placed under a specific folder. I was able to fetch the list of file names from the Folder and its properties, but I need to read the HTML files and parse the 'Pass' or 'Fail' Status to be read and displayed using vba macro.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,349

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    Welcome to VBForums

    Thread moved from the 'Testers and Testing' forum to the 'Office Development/VBA' forum.

  3. #3
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,545

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    Can you zip and attach an example of the file?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,882

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    . I was able to fetch the list of file names from the Folder and its properties
    can you post the code you have to do this

    depending on the complexity and size of the html files it may be adequate to read them as text files

    Code:
    myfoler = "C:\temp\"
    htmlfile = dir(myfolder & "*.html")   'get first file
    do while len(htmlfile) > 0   ' exit after last file
        f = freefile
        open myfolder & htmlfile for input as f
        sfile = input(lof(f), #f)
        Close f
        if instr(sfile, "Pass") > 0 then ' do what ever with pass files
             msgbox sfile & " is a Pass"
        end if
        htmlfile = dir    ' get next file
    loop
    i just typed this in the browser so it may contain typos or code errors, you can generate lists of pass and Fail, to use at completion of reading the files or whatever you want to do

    if the html files are more complex it may be required to parse them as html documents, but until we see a sample, hard to tell
    Last edited by westconn1; Dec 7th, 2018 at 06:26 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    4

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    Quote Originally Posted by vbfbryce View Post
    Can you zip and attach an example of the file?
    Hi,
    Thanks for the reply. I have attached the File manager vba code where all the files from folder are listed. Also, am restricted to attach the HTML file, so the html file image is attached.
    Attached Images Attached Images  
    Attached Files Attached Files

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    4

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    Quote Originally Posted by westconn1 View Post
    can you post the code you have to do this

    depending on the complexity and size of the html files it may be adequate to read them as text files

    Code:
    myfoler = "C:\temp\"
    htmlfile = dir(myfolder & "*.html")   'get first file
    do while len(htmlfile) > 0   ' exit after last file
        f = freefile
        open myfolder & htmlfile for input as f
        sfile = input(lof(f), #f)
        Close f
        if instr(sfile, "Pass") > ) then ' do what ever with pass files
             msgbox sfile & " is a Pass"
        end if
        htmlfile = dir    ' get next file
    loop
    i just typed this in the browser so it may contain typos or code errors, you can generate lists of pass and Fail, to use at completion of reading the files or whatever you want to do

    if the html files are more complex it may be required to parse them as html documents, but until we see a sample, hard to tell

    Hello,

    Thanks for the reply. I have attached the File manager file and sample html file.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,882

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    i am not sure what all the code for your file manager has to do with the original question

    from the image it looks like it may be necessary to parse the html in the files to return the desired result, but i would need an actual sample file or 2 with the html code, to be able to tell, there should no reason why an html file can not be attached once zipped, unless it is above the size limit
    is the field you want to read the overall status? or in the table?

    i corrected a typo i noticed in the code i posted previously
    if you test with that code does it give any useful result?
    change the myfolder to a valid folder on your machine, containing a few files to test with
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    4

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    Quote Originally Posted by westconn1 View Post
    i am not sure what all the code for your file manager has to do with the original question

    from the image it looks like it may be necessary to parse the html in the files to return the desired result, but i would need an actual sample file or 2 with the html code, to be able to tell, there should no reason why an html file can not be attached once zipped, unless it is above the size limit
    is the field you want to read the overall status? or in the table?

    i corrected a typo i noticed in the code i posted previously
    if you test with that code does it give any useful result?
    change the myfolder to a valid folder on your machine, containing a few files to test with
    I think, i need to rephrase the question or explain in detail. Using the File manager, I can browse the local folders and get the list of File names displayed. In the list of files displayed, there are a few HTML files (Output file from selenium which has TC executed with 'pass' or 'Fail' status). When getting the list of file names and properties using the File manager, it should also parse the html files and display the data, that means it should get the 'Pass or Fail' value from the HTML file.

    Sorry about the HTML, since the selenium results contain the client application details am not suppose to attach the file instead the sample image is pasted here.
    And Yes, I want to read the "overall status" value and display.

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    23,882

    Re: Read 'Pass' or 'Fail' Status from multiple html files placed under a folder using

    contain the client application details am not suppose to attach the file
    edit confidential details before posting, but i would need to see the html, to find a returnable value

    When getting the list of file names and properties using the File manager, it should also parse the html files and display the data, that means it should get the 'Pass or Fail' value from the HTML file.
    is there already a specific button or click event you want to use to do this? i looked over the exiting code, but did not find any where this should happen, i may easily have missed something, also what did you want to do with the result from each file?

    could there be other (non selenium) html files in the same folder?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width