Search code examples
selenium-chromedriverscreen-scraping

Chrome Driver: where is dynamic div element?


I'm trying to scrape the price from this page: https://www.samsclub.com/sams/mm-pinto-beans-12lb/prod21002291.ip?xid=plp:product:1:2

enter image description here

The price is in a div that I can see in the element using Dev Tools but it's not in the page source so my research tells me that it's probably a dynamically generated div element. More reading recommended Chrome Driver which returns the data with the dynamic div element but I'm finding it's not there. It's just like viewing page source from the browser.

 ChromeDriver driver = new ChromeDriver(@"C:\chromedriver");
 driver.Url = "https://www.samsclub.com/sams/mm-pinto-beans-12lb/prod21002291.ip?xid=plp:product:1:2";
 driver.Navigate();
 var source = driver.PageSource;
 var pathElement = driver.FindElementById("Price-group");

Is there another step for ChromeDriver to retrun the data with the dynamic divs?

Thanks


Solution

  • Price-Group is not an id. it is a class. Try with FindElementByClassName. Hope that club value is selected before findind the price. Coz, I see price value is displayed only fater selecting club

     var pathElement = driver.FindElementByClassName("Price-group");