How to extract dynamic table content from dropdown selections using IMPORTXML in Google Sheets

I’m trying to pull data from a website that has a dropdown menu with multiple choices. I can get the dropdown values themselves working fine with this formula:

=IMPORTXML("https://example-stocks.com/DataHistory", "//select[@name='stockpicker']/option/@value")

The problem is I need to grab table data that changes based on which dropdown item gets selected. The specific data I want is located at this xpath:

/html/body/div[3]/div/table/tbody/tr/td/div[1]/table/tbody/tr[2]/td/table/tbody/tr[4]/td[3]

I tried building URLs by adding the dropdown values to the base URL like this:

="https://example-stocks.com/DataHistory?stockpicker=" & B2

Where column B contains the dropdown options from my first formula. This approach works on some sites but not this one. I think the issue is that this website uses JavaScript to update the table instead of loading new pages for each selection. Anyone know how to handle this type of dynamic content with IMPORTXML?

IMPORTXML can’t handle JavaScript-rendered content - it only grabs the initial HTML before any scripts run. That’s why your URL parameters aren’t working.

I hit this same wall last year scraping financial data. Those dropdown menus trigger JavaScript that makes AJAX calls to update the table, but IMPORTXML never sees those changes since it can’t run JavaScript.

Your best move is checking if they have an API or finding the actual endpoint URLs the JavaScript hits. Open your browser’s dev tools and watch the network tab while you change dropdown options. You might find direct API endpoints returning JSON data that you can pull with other Sheets functions.

If you need more control, try Google Apps Script with UrlFetchApp instead - though that requires actual programming vs simple IMPORTXML formulas.

i know its really annoying! ImportXML just cant do it with js-rendered stuff. have you thought about using google apps script? you can use puppeteer to mimic dropping and pulling data. it’s not that easy, but can be way more effective!

Had the same issue with real estate listing sites. IMPORTXML can’t handle content that loads via JavaScript after the page renders. Here’s what worked for me: check the site’s robots.txt and sitemap files first - they sometimes have direct data URLs that skip the dropdown completely. Also inspect the page source for hidden parameters or alternative endpoints. You could try Google Apps Script with HtmlService to create a custom function that waits for JavaScript to run, but it’s more work than basic IMPORTXML. If you really need this data, browser automation tools outside Sheets might be worth the extra complexity. Bottom line - IMPORTXML only works with static HTML, not dynamic web apps.