I'm getting a null reference exception with this on the line below when I try to add what is a regular string to a list. I added the extra .
PhotoUrls.Add(images[i].GetAttribute("href").ToString());
Even though when I hover over it in the debugger it is showing it as a string with a value in that line. Here's the full method for context.
public static List<String> Process()
{
List<String> PhotoUrls = null;
try
{
WaitForReady(driver, TimeSpan.FromSeconds(2));
driver.ExecuteScript("window.scrollTo(0,4000);");
var images = driver.FindElementsByCssSelector(".v1Nh3 a");
for (int i = 0; i < images.Count; i++)
{
PhotoUrls.Add(images[i].GetAttribute("href").ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return PhotoUrls;
}