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.
Related
I've made a node.js script like this:
const { Builder, By, Key, until } = require('selenium-webdriver');
const driver = new Builder().forBrowser("firefox").build();
const search_query = 'tigers';
(async () => {
await driver.get(`https://www.google.com/search?q=${search_query}`);
const h3Elements = await driver.findElements(By.css('h3'));
for (const h3 of h3Elements) {
console.log(await h3.getText());
}
console.log('...Task Complete!')
})();
and now I want to test it on a heroku server
but sadly I have no experience or understanding when it comes to setup
I tried following these link:
How to use Selenium Webdriver on Heroku?
How to run Selenium-Webdriver on Heroku with node.js (Firefox or Chrome)
but neither are for firefox
so how do I launch the above script on a heroku server? and what exactly is the process that is going on when it comes to web drivers on the server?
EDIT
I've added https://github.com/hamitaksln/heroku-integrated-firefox-geckodriver as a build pack
and set configuration vars as such:
FIREFOX_BIN=/app/vendor/firefox/firefox
GECKODRIVER_PATH=/app/vendor/geckodriver/geckodriver
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib:/app/vendor
PATH=/usr/local/bin:/usr/bin:/bin:/app/vendor/
but it still shows an ERROR of incorrect path to geckodriver
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. 🤷♂️
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()
We use PhantomJS as simple test runner like this:
phantomjs path/to/test.js
Is there a similar way with headless chrome?
Selenium WebDriver is a NPM package that can help you to run a headless browser.
Try the below example:
const chrome = require('selenium-webdriver/chrome');
const {Builder, By, Key, until} = require('selenium-webdriver');
const width = 640;
const height = 480;
let driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(
new chrome.Options().headless().windowSize({width, height}))
.build();
driver.get('http://www.google.com/ncr')
.then(_ =>
driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN))
.then(_ => driver.wait(until.titleIs('webdriver - Google Search'), 1000))
.then(
_ => driver.quit(),
e => driver.quit().then(() => { throw e; }));
According to the API, the driver methods return Promises and, as a result, can be called using the async/await syntax:
const chrome = require('selenium-webdriver/chrome');
const {Builder, By, Key, until} = require('selenium-webdriver');
async function test() {
const width = 640;
const height = 480;
let driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(
new chrome.Options().headless().windowSize({width, height}))
.build();
await driver.get('http://www.google.com/ncr')
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN))
await driver.wait(until.titleIs('webdriver - Google Search'), 1000))
await driver.quit()
}
test();
You can run you tests with Karma and headless Chrome. Here's a guide for doing that.
Puppeteer's also pretty well-equipped to do this. Here's a guide for that too.
You're looking for Puppeteer, an API for headless Chrome/Chromium.
Once you have your script (the docs are good), you can run it with node script.js.
as explained on developers.google you have option of using Node or Selenium, in either case you will have to re-write part of your test cases to use the new api instead of the phantomjs api.
The following options are based on Node:
Puppeteer
I suggest you to head over to their github page for installation and usage instructions.
Your test case should be written using the Puppetteer api and run with:
node path/to/test.js
There is a list of puppeteer resources, you can use puppeteer with jest, mocha, angular, e2e..
chrome-remote-interface
library
chrome-remote-interface is a lower-level library than Puppeteer's API. I recommend it if you want to be close to the metal and use the DevTools protocol directly.
You need to start chrome in headless mode or use lighthouse or nodejs:
node --inspect=9222 path/to/test.js
write your javascript test case using the chrome DevTools protocol and follow the instructions on their github page to install and run your tests.
The other option is using Selenium configured to run headless Chrome. The following options use Selenium:
ChromeDriver
Webdriver
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