Path: blob/trunk/javascript/selenium-webdriver/example/google_search.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* @fileoverview An example WebDriver script.19*20* Before running this script, ensure that Mozilla's geckodriver is present on21* your system PATH: <https://github.com/mozilla/geckodriver/releases>22*23* Usage:24* // Default behavior25* node selenium-webdriver/example/google_search.js26*27* // Target Chrome locally; the chromedriver must be on your PATH28* SELENIUM_BROWSER=chrome node selenium-webdriver/example/google_search.js29*30* // Use a local copy of the standalone Selenium server31* SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar \32* node selenium-webdriver/example/google_search.js33*34* // Target a remote Selenium server35* SELENIUM_REMOTE_URL=http://www.example.com:4444/wd/hub \36* node selenium-webdriver/example/google_search.js37*/3839const { Builder, By, Key, until } = require('..')4041const driver = new Builder().forBrowser('firefox').build()4243driver44.get('http://www.google.com/ncr')45.then((_) => driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN))46.then((_) => driver.wait(until.titleIs('webdriver - Google Search'), 1000))47.then((_) => driver.quit())484950