-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotokoc.spec.js
38 lines (32 loc) · 1.23 KB
/
otokoc.spec.js
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
import { test, expect } from '@playwright/test';
import fs from 'fs';
test('Otokoc', async ({ page }) => {
await page.goto('https://www.otokocikinciel.com/');
await page.goto('https://www.otokocikinciel.com/ikinci-el-araba');
await page.getByRole('combobox', { name: 'Marka' }).selectOption('fiat');
await page.getByRole('combobox', { name: 'Model' }).selectOption('egea');
await page.locator('label').filter({ hasText: 'Dizel' }).click();
await page.locator('label').filter({ hasText: 'Manuel' }).click();
await page.getByRole('button', { name: 'Araç Bul' }).click();
const filePath = './output.json';
const data = { urls: [] };
const button = await page.$('button[name="TÜMÜNÜ ONAYLA"]');
if (button) {
await button.click();
}
while (true) {
const elements = await page.$$('.col-md-4.impression_product');
for (const element of elements) {
const href = await element.$eval('a', (a) => a.href);
data.urls.push(href);
}
const nextButton = await page.$('a[aria-label="İleri"]');
if (nextButton) {
await nextButton.click();
} else {
break;
}
}
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
console.log(`URLs have been saved to ${filePath}.`);
});