I'm trying to run Selenium in an existing Firefox profile using Node.js. However, Node keeps saying that it can't find the profile. I'm running Arch Linux and Firefox 87. My code:
const webdriver = require("selenium-webdriver");
const firefox = require("selenium-webdriver/firefox");
const geckodriver = require("geckodriver"); //Did this instead of adding geckodriver to Path
const firefoxOptions = new firefox.Options();
const firefoxProfile = '/home/user_name/.mozilla/firefox/l6mcped3.selenium-test/';
firefoxOptions.setProfile(firefoxProfile);
let driver = new webdriver.Builder()
.forBrowser("firefox")
.setFirefoxOptions(firefoxOptions)
.build();
The result (running with the Firefox profile closed):
Running...
node:internal/process/promises:245
triggerUncaughtException(err, true /* fromPromise */);
^
[Error: ENOENT: no such file or directory, stat '/home/user_name/.mozilla/firefox/l6mcped3.selenium-test/lock'] {
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '/home/user_name/.mozilla/firefox/l6mcped3.selenium-test/lock'
However, ls shows the file exists. User permission shouldn't be an issue, but I tried running as sudo anyway and got the same result. Please help. Thanks.
Try deleting the symlink. That has worked for me. 🤷♂️
Related
I'm building a static blog using Nextjs 13 and deploying it on Vercel. I builded and started the project locally and everything was working, but on Vercel I got this error:
ERROR Error: ENOENT: no such file or directory, open 'posts/second.md' at Object.openSync (node:fs:600:3) at Object.readFileSync (node:fs:468:35) at getPostBySlug (/var/task/.next/server/chunks/207.js:146:63) at Post (/var/task/.next/server/app/posts/[slug]/page.js:603:52) at T (/var/task/.next/server/chunks/760.js:11441:25) at Ma (/var/task/.next/server/chunks/760.js:11604:33) at Array.toJSON (/var/task/.next/server/chunks/760.js:11397:32) at stringify () at V (/var/task/.next/server/chunks/760.js:11696:53) at ping (/var/task/.next/server/chunks/760.js:11496:43) { errno: -2, syscall: 'open', code: 'ENOENT', path: 'posts/second.md'}
The error happens when I go to the "/posts/second" route for example, not in the main page
This is the code interested:
const getPostBySlug = (slug: string) => {
const folder = "posts/";
const file = `${folder}${slug}.md`;
const content = fs.readFileSync(file, "utf8");
return matter(content)
};
The posts folder is located in the root folder.
I tried to modify the next config by adding the output option and setting it to 'standalone':
const nextConfig = {
// config
output: 'standalone',
}
I also tried to modify the path to locate the folder but nothing seems to work.
If more information is needed. project is published on GitHub
I solved my problem by looking at a tutorial provided by Vercel, so thanks to this line of code path.join(process.cwd(), 'posts'); the folder path is resolved.
When trying to run Selenium on Windows 10 Edge Chrome version 80, I am getting the following error:
Z:\node_modules\selenium-webdriver\lib\promise.js:2626
throw error;
^
WebDriverError: Unknown error
at parseHttpResponse (Z:\node_modules\selenium-webdriver\lib\http.js:536:11)
at Z:\node_modules\selenium-webdriver\lib\http.js:441:30
at processTicksAndRejections (internal/process/task_queues.js:97:5)
From: Task: WebDriver.createSession()
[...]
I am building it like this:
const webdriver = require('selenium-webdriver'),
edge = require('selenium-webdriver/edge');
var service = new edge.ServiceBuilder()
.setPort(55555)
.build();
var options = new edge.Options();
driver = edge.Driver.createSession(options, service);
Does anyone see why this might be happening? Has anyone had success building the driver using the javascript bindings and can share how they were able to do that?
I'm confident that I have the correct version of the Microsoft Edge Driver
/* In another command prompt window enter the command:
msedgedriver.exe --verbose
Then run the script as normal in the other command prompt
*/
const Selenium = require("selenium-webdriver");
const BROWSER_NAME = Selenium.Browser.EDGE;
const builder = new Selenium.Builder().forBrowser(BROWSER_NAME)
.withCapabilities({
"browserName": 'MicrosoftEdge',
"browserVersion": '81.0',
"platformName": 'Windows 10',
'ms:edgeChromium': true
}).usingServer('http://localhost:9515')
const driver = builder.build()
I have been developing a web app (for a few months) that is built on top of CRA. Everything has been working as intended until this morning when I realized that the npm (or yarn) start script is no longer reusing the existing tab I have open in Chrome. It instead opens a new tab at localhost:3000 even if there are existing tabs at localhost:3000. I have been investigating this for a few hours but am yet to find a solution. I added a log statement in the CRA script (within my node modules) that handles the reusing of existing tabs upon startup of the app.
function startBrowserProcess(browser, url) {
// If we're on OS X, the user hasn't specifically
// requested a different browser, we can try opening
// Chrome with AppleScript. This lets us reuse an
// existing tab when possible instead of creating a new one.
const shouldTryOpenChromeWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME);
if (shouldTryOpenChromeWithAppleScript) {
try {
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
execSync('ps cax | grep "Google Chrome"');
execSync('osascript openChrome.applescript "' + encodeURI(url) + '"', {
cwd: __dirname,
stdio: 'ignore',
});
return true;
} catch (err) {
console.log(err);
// Ignore errors.
}
}
This is the output of the log statement:
{ Error: Command failed: osascript openChrome.applescript "http://localhost:3000/"
at checkExecSyncError (child_process.js:621:11)
at execSync (child_process.js:658:13)
at startBrowserProcess (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-dev-utils/openBrowser.js:78:7)
at openBrowser (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-dev-utils/openBrowser.js:122:14)
at Server.devServer.listen.err (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-scripts/scripts/start.js:100:7)
at Server.returnValue.listeningApp.listen (/Users/***/Desktop/WorkSpace/React/***/node_modules/webpack-dev-server/lib/Server.js:604:10)
at Object.onceWrapper (events.js:273:13)
at Server.emit (events.js:182:13)
at emitListeningNT (net.js:1328:10)
at process.internalTickCallback (internal/process/next_tick.js:72:19)
status: 1,
signal: null,
output: [ null, null, null ],
pid: 2691,
stdout: null,
stderr: null }
It seems to have an issue running the Applescript command that handles this but I am unsure why. One of the other developers that is working on the same app locally is not having this issue. One change I made recently was upgrading to the new macOS Mojave. But the other developer just upgraded as well and is not having this issue.
Does anyone know what could be wrong?
To avoid opening a new tab,
you'll need to create an .env file in the root of your project and add this line,
BROWSER=none.
As shown here
Turns out after I upgraded Mojave I denied interface access to Google Chrome from my terminal. So it was unable to run the "reuse" tab script.
I have my selenium standalone server set up as running with the IEDriver as a parameter using the selenium-standalone start --drivers.ie.arch=ia32 configuration.
I'm getting the following error when I try to run my internet explorer selenium test:
index.js:673
throw new Error('Do not know how to build driver: ' + browser
^
Error: Do not know how to build driver: IE; did you forget to call
usingServer(url)?
Yet I have the correct server listed in my code:
const {Builder, By, Key, until} = require('selenium-webdriver');
driver = await new webdriver.Builder().forBrowser('IE').usingServer('http://localhost:4444/wd/hub').build();
I have also tried this:
let driver = new webdriver.Builder()
.forBrowser('internet explorer')
.usingServer('http://localhost:4444/wd/hub')
.build();
but neither of these work and I get the same error message...
Any help would be appreciated!
https://github.com/SeleniumHQ/selenium/wiki/Grid2 Just read this article, you are missing something. And run your IE tests under administrator for future.
driver = new webdriver.Builder().
usingServer("http://localhost:4444/wd/hub").
withCapabilities(webdriver.Capabilities.ie()).
build();
It works for me.
I'm automating Chrome on Windows 8.1 with JavaScript using Selenium's WebDriverJS. I downloaded a copy of the ChromeDriver and Selenium Standalone Server jar file and placed in E:\Selenium directory. I started Selenium Standalone Server and tried to run my javascript code written in BrowserTest.js file with Node command prompt as
E:\Selenium> Node BrowserTest.js
the BrowserTest.js:
var driver = require("selenium-webdriver");
function createDriver() {
var driver = new driver.Builder()
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities(driver.Capabilities.chrome())
.build();
driver.manage().timeouts().setScriptTimeout(10000);
return driver;
}
var driver = createDriver();
driver.get("http://www.google.com");
driver.getTitle().then(function (title) {
console.log(title);
});
driver.quit();
But it throws error as:
fs.js:500 return binding.open(pathModule._makeLong(path),
stringToFlags(flags), mode);
^ Error: ENOENT, no such file or directory 'E:\Selenium\webdriver\logging.js'
at Error (native)
at Object.fs.openSync (fs.js:500:18)
at Object.fs.readFileSync (fs.js:352:15)
at Object.Context.closure.goog.retrieveAndExecModule_ (E:\Selenium\node_modules\selenium-webdriver\_base.js:129:23)
at <anonymous>:1:6
at Object.exports.runInContext (vm.js:64:17)
at Context.closure.closure.vm.createContext.CLOSURE_IMPORT_SCRIPT (E:\Selenium\node_modules\selenium-webdriver\_base.js:101:12)
at Object.goog.importScript_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:873:9)
at Object.goog.importModule_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:894:14)
at Object.goog.writeScripts_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:1251:16)
Update
try changing the selenium-webdriver version to 2.46.1, it has been pushed to npm and in it, the bug has been fixed.
like #simon said, this bug is already been reported in github,
for now, one hack has been suggested as solution in it's comments,
go to node_modules\selenium-webdriver\_base.js, add below line between line 100 and line 101( as first line of if block):
opt_srcText = opt_srcText.replace(/\\/g,'/');
it fixed the problem for me.
There appears to be a bug in v2.46.0 of Selenium on windows.
It has just been fixed in 2.46.1, so if you update it should solve your problem
Problem was solved by updating to version - 2.46.1