From 77fc45425c1216e03d5ad2c22986383db1d09b72 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Sat, 3 Mar 2018 12:00:14 -0600 Subject: [PATCH] Hopefully a fix for #404, null ref while giving suggestions --- src/canopy/canopy.fs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index 3afed3e6..e4cbe4bc 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -1,6 +1,7 @@ [] module canopy.core +open System.Collections.ObjectModel open OpenQA.Selenium.Firefox open OpenQA.Selenium open OpenQA.Selenium.Interactions @@ -189,10 +190,12 @@ let private suggestOtherSelectors cssSelector = } } return texts;""" - let classes = js classesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> "." + item.ToString()) |> Array.ofSeq - let ids = js idsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> "#" + item.ToString()) |> Array.ofSeq - let values = js valuesViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq - let texts = js textsViaJs :?> System.Collections.ObjectModel.ReadOnlyCollection |> Seq.map (fun item -> item.ToString()) |> Array.ofSeq + let safeSeq orig = if orig = null then Seq.empty else orig + let safeToString orig = if orig = null then "" else orig.ToString() + let classes = js classesViaJs :?> ReadOnlyCollection |> safeSeq |> Seq.map (fun item -> "." + safeToString item) |> Array.ofSeq + let ids = js idsViaJs :?> ReadOnlyCollection |> safeSeq |> Seq.map (fun item -> "#" + safeToString item) |> Array.ofSeq + let values = js valuesViaJs :?> ReadOnlyCollection |> safeSeq |> Seq.map (fun item -> safeToString item) |> Array.ofSeq + let texts = js textsViaJs :?> ReadOnlyCollection |> safeSeq |> Seq.map (fun item -> safeToString item) |> Array.ofSeq let results = Array.append classes ids