baptx

google_search_selenium-webdriver.node

Apr 23rd, 2021
729
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /*
  2.  * Test based on:
  3.  * https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Your_own_automation_environment#Setting_up_Selenium_in_Node
  4.  * https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode
  5.  */
  6.  
  7. var webdriver = require("selenium-webdriver"),
  8.     By = webdriver.By,
  9.     until = webdriver.until;
  10.  
  11. var firefox = require("selenium-webdriver/firefox");
  12.  
  13. var options = new firefox.Options();
  14. //options.addArguments("-headless");
  15.  
  16. var driver = new webdriver.Builder()
  17.     .forBrowser("firefox")
  18.     .setFirefoxOptions(options)
  19.     .build();
  20.  
  21. driver.get("https://www.google.com/?hl=en");
  22.  
  23. driver.findElement(By.name("q")).sendKeys("webdriver");
  24.  
  25. driver.wait(until.elementIsVisible(driver.findElement(By.name("btnK")))).then(function (el) {
  26.     el.click();
  27.    
  28.     driver.wait(function () {
  29.         return driver.getTitle().then(function (title) {
  30.             console.log(title);
  31.             return title === "webdriver - Google Search";
  32.         });
  33.     }, 1000).then(function (result) {
  34.         console.log("Test passed");
  35.         driver.quit();
  36.     }, function () {
  37.         console.log("Test failed");
  38.         driver.quit();
  39.     });
  40. });
  41.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×