1

Hey I want to get screen shot with nodejs selinium-webdriver firefox

I am getting error like that : Error: The geckodriver.exe executable could not be found on the current PATH.

I set up the enviornment variable, but no luck

Affan Shaikh
  • 51
  • 1
  • 4
  • Possible duplicate of [How to use the gecko executable with Selenium](https://stackoverflow.com/questions/37785686/how-to-use-the-gecko-executable-with-selenium) – Marged Jul 17 '17 at 15:26

2 Answers2

1

You need to set the path to the geckodriver.exe prior to creating the driver instance.

In Java:

System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe");//"<PATH TO LOCATION>\\chromedriver.exe");
smit9234
  • 361
  • 1
  • 7
  • 3
    But this is node js, I am using selenium web driver. – Affan Shaikh Jul 17 '17 at 16:18
  • Can you post what your environment setup is? do you have a spec.js file or equivalent that shows how you setup your webdriver? – smit9234 Jul 17 '17 at 16:24
  • var webdriver = require('selenium-webdriver'); By = require('selenium-webdriver').By; until = require('selenium-webdriver').untill; fs = require('fs'); var chromedriver = require('chromedriver'); firefox = require('selenium-webdriver/firefox'); //driver = new FirefoxDriver(); var driver = new webdriver.Builder() .forBrowser('firefox') .build(); – Affan Shaikh Jul 17 '17 at 16:27
  • driver.manage().window().maximize(); driver.manage().deleteAllCookies(); driver.get(http://...'); driver.manage().window().setSize(1349,873); driver.takeScreenshot().then(function(data){ fs.writeFileSync('img.png',data,'base64'); }); driver.quit(); – Affan Shaikh Jul 17 '17 at 16:27
  • Take a look here https://dinosaurscode.xyz/tutorials/2016/07/29/selenium-2-using-node-js/ and here https://team.goodeggs.com/getting-started-with-selenium-webdriver-for-node-js-f262a00c52e1. You need to include the driver capabilities. – smit9234 Jul 17 '17 at 16:35
  • @smit9234 Both links you provided are broken. – Fusion Jun 22 '20 at 15:21
  • How to set `geckodriver` path with javascript in Node? – mr.boris Jan 26 '21 at 10:27
1

I had some successful result with this process:

1° - Check if your webdriver(geckodriver, chromedriver, etc.) is in the correct path (if you don't know how to do it, check the link, https://www.youtube.com/watch?v=fj0Ud16YJJw). I think this video is a little old, because in npm the code information is different, updated, but it also serves as instruction.

2°- I changed my type of license(in package.json) from “ISC” to “MIT”, you can do this manually. And for my surprise, this change made my code go well.

const webdriver = require("selenium-webdriver");
const firefox = require("selenium-webdriver/firefox");

const { Builder, Browser, By, Key, until } = require("selenium-webdriver");

async function example() {
  let driver = await new Builder().forBrowser(Browser.FIREFOX).build();
  try {
    await driver.get("https://www.google.com/ncr");
    await driver.findElement(By.name("q")).sendKeys("Selenium", Key.RETURN);
    await driver.wait(until.titleIs("webdriver - Google Search"), 1000);
  } finally {
    await driver.quit();
  }
}

example();

And here we have another link that goes to selenium webdriver dependency in npm website(https://www.npmjs.com/package/selenium-webdriver) for more information.

MouraCass
  • 11
  • 2