I had asked similar questions some time back and I am still facing errors trying to parse a webpage. The scenario is that the system navigates to https://shop.sprouts.com/shop/flyer and wants to extract each of the specials related to each category. Currently when a category is clicked, I see a blank screen on the right hand side. I have tried both the options below but I get the same results.
elementLeftHandSideMenu.Click();
iJavaScriptExecutor.ExecuteScript("arguments[0].click();", elementLeftHandSideMenu);
Is this a timing issue? What am I doing wrong?
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using SeleniumExtras.WaitHelpers;
using System.Threading;
using System.Collections.Generic;
using Newtonsoft.Json;
[TestClass]
public class UnitTest1
{
ChromeDriver driver;
WebDriverWait webDriverWait;
[TestInitialize]
public void Startup()
{
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--proxy-server='direct://'");
chromeOptions.AddArguments("--proxy-bypass-list=*");
chromeOptions.AddArguments("--start-maximized");
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(path);
driver = new ChromeDriver(chromeDriverService, chromeOptions);
webDriverWait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
}
[TestCleanup]
public void CleanUp()
{
driver.Quit();
}
[TestMethod]
public void GetSproutsWeeklyAdDetails2()
{
try
{
driver.Navigate().GoToUrl("https://shop.sprouts.com/shop/flyer");
}
catch (TimeoutException timeoutException)
{
driver.Navigate().Refresh();
}
var iJavaScriptExecutor = (IJavaScriptExecutor)driver;
webDriverWait.Until(driver1 => iJavaScriptExecutor.ExecuteScript("return document.readyState").Equals("complete"));
var elementsLeftHandSideMenu = webDriverWait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(
By.XPath("//ul[@class='menu sidenav']/li[@class='child']/a")));
System.Diagnostics.Debug.WriteLine(elementsLeftHandSideMenu.Count);
var items = new List<Item>();
foreach (var elementLeftHandSideMenu in elementsLeftHandSideMenu)
{
Thread.Sleep(2000);
try
{
elementLeftHandSideMenu.Click();
//iJavaScriptExecutor.ExecuteScript("arguments[0].click();", elementLeftHandSideMenu);
}
catch (Exception exception)
{
System.Diagnostics.Debug.WriteLine(exception.ToString());
}
//parsing code here does not work as the RHS shows a blank page
System.Diagnostics.Debug.WriteLine("Exit");
}
}
}