import { chromium } from 'playwright'; const TEST_URL = 'https://curaleaf.com/stores/curaleaf-dispensary-48th-street'; async function testCuraleafAdvanced() { console.log('\nšŸŽ­ Testing Curaleaf with Advanced Playwright Techniques\n'); const browser = await chromium.launch({ headless: true, args: [ '--no-sandbox', '--disable-setuid-sandbox' ] }); try { const context = await browser.newContext({ userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', viewport: { width: 1280, height: 720 }, locale: 'en-US', timezoneId: 'America/Phoenix', geolocation: { longitude: -112.0740, latitude: 33.4484 }, // Phoenix, AZ permissions: ['geolocation'] }); const page = await context.newPage(); // Navigate directly console.log('šŸ“ Navigating to age gate page...'); await page.goto(TEST_URL, { waitUntil: 'networkidle', timeout: 60000 }); const currentUrl = page.url(); console.log(`Current URL: ${currentUrl}`); if (!currentUrl.includes('/age-gate')) { console.log('āœ… No age gate - page loaded directly!'); return; } console.log('\nšŸ“ Age gate detected. Analyzing page structure...'); // Wait for age gate to fully render await page.waitForTimeout(2000); // Take screenshot await page.screenshot({ path: '/tmp/curaleaf-adv-before.png', fullPage: true }); console.log('šŸ“ø Before screenshot: /tmp/curaleaf-adv-before.png'); // Get all interactive elements console.log('\nšŸ” Finding interactive elements...'); // Method 1: Check for the state dropdown using multiple selectors const dropdownSelectors = [ 'button#state', 'button[id="state"]', '[role="combobox"]', 'button:has-text("Select")', 'button:has-text("State")' ]; let dropdownFound = false; for (const selector of dropdownSelectors) { const count = await page.locator(selector).count(); if (count > 0) { console.log(`āœ… Found dropdown with selector: ${selector}`); dropdownFound = true; // Click to open await page.locator(selector).first().click(); await page.waitForTimeout(1500); // Look for Arizona in various ways const arizonaSelectors = [ '[role="option"]:has-text("Arizona")', 'text=Arizona', '[data-value="Arizona"]', '[data-value="AZ"]' ]; for (const azSelector of arizonaSelectors) { const azCount = await page.locator(azSelector).count(); if (azCount > 0) { console.log(`āœ… Found Arizona with selector: ${azSelector}`); await page.locator(azSelector).first().click(); await page.waitForTimeout(2000); // Take screenshot after state selection await page.screenshot({ path: '/tmp/curaleaf-adv-after-state.png' }); console.log('šŸ“ø After state selection: /tmp/curaleaf-adv-after-state.png'); // Look for continue/submit button const submitSelectors = [ 'button:has-text("Continue")', 'button:has-text("Submit")', 'button:has-text("Enter")', 'button:has-text("Confirm")', 'button[type="submit"]', 'a:has-text("Continue")' ]; for (const submitSel of submitSelectors) { const submitCount = await page.locator(submitSel).count(); if (submitCount > 0) { console.log(`āœ… Found submit button: ${submitSel}`); // Click and wait for navigation const [response] = await Promise.all([ page.waitForNavigation({ timeout: 10000 }).catch(() => null), page.locator(submitSel).first().click() ]); await page.waitForTimeout(3000); break; } } break; } } break; } } if (!dropdownFound) { console.log('āŒ No dropdown found. Checking page HTML...'); const html = await page.content(); console.log('\nPage HTML (first 1000 chars):'); console.log(html.substring(0, 1000)); } // Check final state const finalUrl = page.url(); console.log(`\nFinal URL: ${finalUrl}`); await page.screenshot({ path: '/tmp/curaleaf-adv-final.png', fullPage: true }); console.log('šŸ“ø Final screenshot: /tmp/curaleaf-adv-final.png'); if (finalUrl.includes('/age-gate')) { console.log('āŒ Still at age gate'); // Try to get cookies anyway const cookies = await context.cookies(); console.log('\nCurrent cookies:'); cookies.forEach(c => console.log(` ${c.name}: ${c.value}`)); } else { console.log('āœ… Successfully bypassed age gate!'); // Save successful cookies const cookies = await context.cookies(); console.log('\nSuccessful cookies:'); cookies.forEach(c => console.log(` ${c.name}: ${c.value}`)); } } catch (error) { console.error('āŒ Error:', error); } finally { await browser.close(); console.log('\nāœ… Test completed'); } } testCuraleafAdvanced();