baptx

tarteaucitron_deny_cookies_selenium-webdriver.node

Apr 23rd, 2021 (edited)
247
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://tarteaucitron.io/en/");
  22.  
  23. // https://stackoverflow.com/questions/25753014/selenium-webdriver-wait-till-element-is-displayed/29156163#29156163
  24. driver.wait(until.elementLocated(By.id("tarteaucitronAllDenied2"))).then(function(el) {
  25. //driver.wait(until.elementIsVisible(driver.findElement(By.id("tarteaucitronAllDenied2")))).then(function(el) { // not working
  26.     driver.sleep(1000).then(function() { // necessary to make the click work
  27.         el.click();
  28.         //driver.quit();
  29.     });
  30. //});
  31. });
  32.  
RAW Paste Data