112 lines
3.7 KiB
JavaScript
112 lines
3.7 KiB
JavaScript
|
|
import auth from './tools/siemens-auth.js';
|
||
|
|
|
||
|
|
console.log('=== Testing NX Open Python Reference Access ===\n');
|
||
|
|
|
||
|
|
const browser = await auth.getBrowser();
|
||
|
|
const page = await browser.newPage();
|
||
|
|
await page.setViewport({ width: 1400, height: 900 });
|
||
|
|
await auth.loadCookies(page);
|
||
|
|
|
||
|
|
const url = 'https://docs.sw.siemens.com/en-US/doc/209349590/PL20200522120320484.nxopen_python_ref?audience=external';
|
||
|
|
console.log('Loading:', url);
|
||
|
|
await page.goto(url, { waitUntil: 'networkidle2' });
|
||
|
|
await new Promise(r => setTimeout(r, 5000));
|
||
|
|
|
||
|
|
// Handle cookie popup - click multiple times if needed
|
||
|
|
for (let i = 0; i < 3; i++) {
|
||
|
|
const cookieBtn = await page.evaluateHandle(() => {
|
||
|
|
const btns = Array.from(document.querySelectorAll('button'));
|
||
|
|
return btns.find(b => b.innerText && b.innerText.includes('Accept All Cookies'));
|
||
|
|
});
|
||
|
|
if (cookieBtn && cookieBtn.asElement()) {
|
||
|
|
console.log('Clicking Accept All Cookies...');
|
||
|
|
await cookieBtn.asElement().click();
|
||
|
|
await new Promise(r => setTimeout(r, 1000));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
await new Promise(r => setTimeout(r, 3000));
|
||
|
|
await page.screenshot({ path: '/tmp/nxopen-1.png' });
|
||
|
|
|
||
|
|
// Check for iframes
|
||
|
|
const frames = page.frames();
|
||
|
|
console.log('\nFrames found:', frames.length);
|
||
|
|
frames.forEach((f, i) => console.log(` Frame ${i}: ${f.url().substring(0, 80)}`));
|
||
|
|
|
||
|
|
// Look for documentation iframe
|
||
|
|
let docFrame = null;
|
||
|
|
for (const frame of frames) {
|
||
|
|
const frameUrl = frame.url();
|
||
|
|
if (frameUrl.includes('nxopen') || frameUrl.includes('doxygen') || frameUrl.includes('/doc/')) {
|
||
|
|
docFrame = frame;
|
||
|
|
console.log('\nFound doc frame:', frameUrl);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// If no iframe, check the main page content
|
||
|
|
console.log('\n=== Main Page Content ===');
|
||
|
|
const mainContent = await page.evaluate(() => {
|
||
|
|
// Get all text
|
||
|
|
const text = document.body.innerText;
|
||
|
|
// Look for specific elements
|
||
|
|
const title = document.title;
|
||
|
|
const h1s = Array.from(document.querySelectorAll('h1')).map(h => h.innerText);
|
||
|
|
const h2s = Array.from(document.querySelectorAll('h2')).map(h => h.innerText);
|
||
|
|
|
||
|
|
return { title, h1s, h2s, text: text.substring(0, 2000) };
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('Title:', mainContent.title);
|
||
|
|
console.log('H1s:', mainContent.h1s);
|
||
|
|
console.log('H2s:', mainContent.h2s);
|
||
|
|
|
||
|
|
// Try clicking on "Classes" tab
|
||
|
|
console.log('\n=== Trying to click Classes ===');
|
||
|
|
const classesTab = await page.evaluateHandle(() => {
|
||
|
|
const elements = Array.from(document.querySelectorAll('*'));
|
||
|
|
return elements.find(e => e.innerText === 'Classes' || e.innerText === 'Classes▼');
|
||
|
|
});
|
||
|
|
|
||
|
|
if (classesTab && classesTab.asElement()) {
|
||
|
|
console.log('Found Classes element, clicking...');
|
||
|
|
await classesTab.asElement().click();
|
||
|
|
await new Promise(r => setTimeout(r, 3000));
|
||
|
|
await page.screenshot({ path: '/tmp/nxopen-2.png' });
|
||
|
|
|
||
|
|
// Get dropdown content
|
||
|
|
const dropdownContent = await page.evaluate(() => {
|
||
|
|
const links = Array.from(document.querySelectorAll('a'));
|
||
|
|
return links
|
||
|
|
.filter(a => a.innerText && a.href)
|
||
|
|
.map(a => a.innerText.trim())
|
||
|
|
.filter(t => t.length > 2 && t.length < 100)
|
||
|
|
.slice(0, 50);
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('Dropdown links:', dropdownContent.length);
|
||
|
|
dropdownContent.slice(0, 30).forEach(l => console.log(' -', l));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Try to find the embedded documentation content
|
||
|
|
console.log('\n=== Looking for embedded content ===');
|
||
|
|
const embeddedContent = await page.evaluate(() => {
|
||
|
|
// Look for common documentation containers
|
||
|
|
const containers = document.querySelectorAll('iframe, .doc-content, .documentation, #content, main');
|
||
|
|
const results = [];
|
||
|
|
containers.forEach(c => {
|
||
|
|
results.push({
|
||
|
|
tag: c.tagName,
|
||
|
|
id: c.id,
|
||
|
|
className: c.className,
|
||
|
|
src: c.src || null
|
||
|
|
});
|
||
|
|
});
|
||
|
|
return results;
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('Found containers:', embeddedContent);
|
||
|
|
|
||
|
|
await auth.closeBrowser();
|
||
|
|
console.log('\nDone!');
|