-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.js
28 lines (22 loc) · 872 Bytes
/
sample.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
/*
* Derived from https://www.selenium.dev/documentation/en/ [2020-07-18]
* Usage: node sample
*/
const {Builder, By, Key, until} = require('selenium-webdriver');
var firefox = require('selenium-webdriver/firefox');
(async function example() {
var options = new firefox.Options();
options.addArguments("-headless");
let driver = await new Builder().forBrowser('firefox').setFirefoxOptions(options).build();
try {
// Navigate to Url
await driver.get('https://www.google.com');
// Enter text "cheese" and perform keyboard action "Enter"
await driver.findElement(By.name('q')).sendKeys('cheese', Key.ENTER);
let firstResult = await driver.wait(until.elementLocated(By.css('h3')), 10000);
console.log(await firstResult.getAttribute('textContent'));
}
finally{
driver.quit();
}
})();