Created
April 10, 2020 17:56
-
-
Save jaffamonkey/60aa41aacef5463d0ee7ee5e53a4d484 to your computer and use it in GitHub Desktop.
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
// Filename: webdriver-javascript.js | |
// To setup: npm install -g selenium-webdriver chromedriver | |
// To run: node webdriver-javascript.js | |
// The easiest way to look at this, is it's creating an object that's webdriver. | |
var webdriver = require('selenium-webdriver'), | |
By = webdriver.By, | |
until = webdriver.until; | |
var errorMessage = 'Could not locate the correct '; | |
let chrome = require('selenium-webdriver/chrome'); | |
let chromedriver = require('chromedriver'); | |
chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build()); | |
// This is creating an webdriver object which enable interaction with the browser | |
const browser = new webdriver | |
.Builder() | |
.usingServer() | |
.withCapabilities({ | |
'browserName': 'chrome', | |
'chromeOptions': { | |
args: ['headless', 'disable-gpu'] | |
} | |
}).build(); | |
try { | |
browser.get('https://duckduckgo.com'); | |
browser.wait(until.elementLocated(By.name('q')), 3000, errorMessage + 'field').sendKeys('TrumpKlon'); | |
browser.wait(until.elementLocated(By.id('search_button_homepage')), 3000, errorMessage + 'button').click(); | |
browser.wait(until.titleIs('TrumpKlon at DuckDuckGo'), 3000, errorMessage + 'title'); | |
browser.wait(until.elementLocated(By.partialLinkText('TrumpKlon')), 3000, errorMessage + 'link'); | |
} | |
catch (err) { | |
console.log(err); | |
} | |
finally { | |
browser.quit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment