-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-element-detection-debug.js
More file actions
59 lines (48 loc) · 1.94 KB
/
test-element-detection-debug.js
File metadata and controls
59 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { chromium } = require('playwright');
const { AIElementDetector } = require('./dist/detectors/AIElementDetector');
async function testElementDetection() {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
const detector = new AIElementDetector();
console.log('Testing with static HTML...');
await page.setContent(`
<html>
<body>
<button id="test-btn">Click Me</button>
<input type="text" id="test-input" placeholder="Enter text">
<a href="#" id="test-link">Test Link</a>
<form id="test-form">
<input type="email" name="email" required>
<button type="submit">Submit</button>
</form>
</body>
</html>
`);
// Wait for content to be ready
await page.waitForLoadState('domcontentloaded');
// Test individual selectors
console.log('\nTesting individual selectors:');
const buttons = await page.$$('button');
console.log('Buttons found with $$:', buttons.length);
const inputs = await page.$$('input[type="text"]');
console.log('Text inputs found:', inputs.length);
const allInputs = await page.$$('input');
console.log('All inputs found:', allInputs.length);
const links = await page.$$('a[href]');
console.log('Links found:', links.length);
// Test if we can get element properties
if (buttons.length > 0) {
const firstButton = buttons[0];
const text = await firstButton.textContent();
const isVisible = await firstButton.isVisible();
console.log('First button text:', text, 'Visible:', isVisible);
}
// Check if detector has selector patterns
console.log('\nChecking detector properties:');
console.log('Detector has selectorPatterns:', detector.selectorPatterns !== undefined);
if (detector.selectorPatterns) {
console.log('Pattern keys:', Array.from(detector.selectorPatterns.keys()));
}
await browser.close();
}
testElementDetection().catch(console.error);