PuppeteerSharp evaluate expression to complex type?

-1

Hi I am using PuppeteerSharp for the first time and am wondering if EvaulateExpressionAsync supports a way to convert to a complex c# object. So when i try to do something like this:

var allResultsSelector = ".sortableTable.resultTable tr.studyResultRow";

var jsSelectAllAnchors = $"Array.from(document.querySelectorAll('{allResultsSelector}')).map(f=>f.innerText);";

await frmSearch.WaitForSelectorAsync(allResultsSelector);

var urls = await frmSearch.EvaluateExpressionAsync<InteleStudyResult[]>(jsSelectAllAnchors);

c# type for now

    public class InteleStudyResult
    {
        public string PatientName { get; set; }
        //public string PatientId { get; set; }
        //public DateTime DOB { get; set; }
        //public string Sex { get; set; }
        //public string Accession { get; set; }
        //public DateTime StudyDate { get; set; }
        //public string Modality { get; set; }
        //public int? Series { get; set; }
        //public string StudyDescription { get; set; }
    }

exception occurs on the Eval call

Newtonsoft.Json.JsonSerializationException HResult=0x80131500 Message=Error converting value " my string here " to type 'InteleradWebAccessor.InteleStudyResult'. Path '[0]'. Source=Newtonsoft.Json

Inner Exception 1: ArgumentException: Could not cast or convert from System.String to InteleradWebAccessor.InteleStudyResult.

If this is not supported I'd greatly appreciate a suggestion on best way to handle getting what is a html table row into a c# complex type using PuppeteerSharp

c#
puppeteer
puppeteer-sharp
asked on Stack Overflow Apr 1, 2020 by PBMe_HikeIt

1 Answer

0

You should an object in your map

Array.from(document.querySelectorAll('{allResultsSelector}'))
   .map(f =>{ return { patientName: f.innerText} });
answered on Stack Overflow Apr 1, 2020 by hardkoded

User contributions licensed under CC BY-SA 3.0