Reputation: 341
Here is my code, I want to achieve the same thing but with a hidden browser window.
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var path = require('chromedriver').path;
var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
driver.get('https://pk.linkedin.com/in/mahad-waseem-263a06ba');
driver.getTitle().then(function(title){
console.log(title);
});
Upvotes: 0
Views: 502
Reputation: 15780
I don't know of a way to do this if you're running the browser in the same environment where you're doing your development but there are three alternatives that allow you to isolate the browser:
Set up a second PC
Set up a virtual machine
Use the Selenium Docker images to run the browser in a Docker container
These three solutions have one thing in common: they're running the browser in an environment which is isolated from your development environment and headless, so you don't have to deal with browser windows opening and closing on your desktop.
Of the three, I prefer the third one for a couple of reasons:
That last point is probably the most interesting: you may be familiar with Selenium Grid which is a system where you can run your tests against different browsers in parallel. I've always been interested in it, but until recently it looked like too big a project to set it up - you need a host for the grid, plus separate hosts for the browsers you want to test. Well now, thanks to Docker, it is possible to do it all on one host. I'm currently using the Selenium Grid Hub Docker image to test against Chrome and Firefox simultaneously, all from the comfort of my dev machine.
Upvotes: 1