Last active
October 20, 2021 07:34
-
-
Save mjvdende/551f515fdfc11c3c81659231f6791798 to your computer and use it in GitHub Desktop.
Use array of keywords and loop through script in Playwright
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test.only('search search engines', async({page, context}) => { | |
const search = [ | |
{ | |
name: 'yandex', | |
url: 'https://yandex.com/', | |
elementFill: '//input[@aria-label="Request"]', | |
elementResult: '//li[@data-first-snippet] //div[@class="organic__url-text"]' | |
}, | |
{ | |
name: 'google', | |
url: 'https://www.google.nl', | |
elementFill: '//input[@name="q"]', | |
elementResult: '(//h2[@class="result__title"])[9]' | |
}, | |
{ | |
name: '', | |
url: 'https://duckduckgo.com/', | |
elementFill: '//input[@name="q"]', | |
elementResult: '(//h2[@class="result__title"])[9]' | |
} | |
] | |
const kewWordlist = ['Arsenal', 'Liverpool', 'Ajax'] | |
for (let i = 0; i < search.length; i++) { | |
const searchName = search[i].name | |
const searchResult = search[i].elementResult | |
const searchFill = search[i].elementFill | |
const searchPage = await context.newPage() | |
await searchPage.waitForLoadState() | |
await searchPage.goto(`${search[i].url}`) | |
for (let i = 0; i < kewWordlist.length; i++) { | |
await searchPage.fill(searchFill,kewWordlist[i]) | |
await searchPage.keyboard.press('Enter') | |
await searchPage.waitForSelector(searchResult) | |
const result = await page.$(searchResult) | |
console.log(`${searchName}: ${result} `) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment