Placing geckodriver in resources and mapping it works on the machine am working on, but not on any other machine. i need it to export it to other machines, so that i am creating a jar which i need to run on any other machine, but when running the jar on other machine is throwing out "The path to the driver executable must be set by the webdriver.gecko.driver system property" error.
public static WebDriver createDriver()
{
WebDriver driver= new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "./src/main/resources/geckodriver");
driver = new FirefoxDriver(FirefoxDriverProfile());
driver.manage().window().maximize();
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
return driver;
[Please take a look at the image]
https://i.stack.imgur.com/khGBu.png
It seems that you're missing the file extension.
The following works for me using relative file paths:
System.setProperty("webdriver.gecko.driver", ".\\WebDrivers\\geckodriver.exe");
Edit: Have you tried to swap the order of these two lines?
Unless I'm mistaken, the system property should be set prior to the creation of the WebDriver.
WebDriver driver= new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "./src/main/resources/geckodriver");
Should be
System.setProperty("webdriver.gecko.driver", "./src/main/resources/geckodriver");
WebDriver driver= new FirefoxDriver();
You can set it like:-
System.setProperty("webdriver.gecko.driver", new File("./src/main/resources/geckodriver").getCanonicalPath());
Related
How to launch IE browser using selenium webdriver 3.4.0? I have tried, but unable to open an IE browser. I have downloaded IE Driver and followed the same like launching firefox driver.
Launching of Firefox browser is working fine, below are command lines
System.setProperty("webdriver.gecko.driver","C:\\Users\\vidhya.r\\Desktop\\Automation\\Jars\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver(options);
Download IEDriverServer, put it to path or use
System.setProperty("webdriver.ie.driver", ieDriverPath);
launch via
driver = new InternetExplorerDriver();
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capability.setCapability(InternetExplorerDriver.ELEMENT_SCROLL_BEHAVIOR, 1);
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
System.setProperty("webdriver.ie.driver", ieDriverPath);
WebDriver driver = new InternetExplorerDriver(capability);
First download IEDriver from this Link
Use this:
System.setProperty("webdriver.ie.driver", "Path of IE driver");
WebDriver driver = new InternetExplorerDriver();
If you want to add some capabilities then use DesiredCapabilities
How to maximize Chrome browser window using selenium script?
This is my code:
package newpackage;
import org.openqa.selenium.WebDriver;
public class MyClass {
public static void main(String[] args) {
WebDriver Driver=new Chrome();
Driver.get("http://www.google.com");
Driver.manage().window().maximize();
}
}
However, I get this error:
Exception in thread "main" java.lang.NullPointerException
at newpackage.MyClass.main(MyClass.java:10)
To work with Selenium 3.4.0 you need to download the latest chromedriver 2.29 from here and update your Google Chrome to latest release of 58.x. Save the chromedriver in your system and provide the absolute path in your code through System.setProperty as below.
Now, the constructor for initializing ChromeDriver and Chrome Browser is as follows:
WebDriver driver = new ChromeDriver();
WebDriver driver = new ChromeDriver(options);
Note: The method is ChromeDriver() but not Chrome() which have caused java.lang.NullPointerException
Finally, to maximize Chrome browser window using selenium script you need to take help of ChromeOptions class as follows:
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.navigate().to("https://google.com");
//do your actions
driver.quit();
}
In the script you have written the Driver object is null. Try instantiate the Driver properly by using Chromedriver.
System.setProperty("webdriver.chrome.driver", "c:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Driver.get("http://www.google.com");
Driver.manage().window().maximize();
var options = new ChromeOptions();
options.AddArguments("disable-infobars");
options.AddArguments("--start-maximized");
options.AddArguments("--disable-extensions");
var chromeDriver = new ChromeDriver(options);
use driver.manage().window().fullscreen(); instead
It should work.
written a code like this
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
WebDriver driver=new FirefoxDriver();
driver.get("url");
Not working in firefox how to resolve this one.
You're not creating the driver with the profile - you're creating it with an empty constructor. Try WebDriver driver=new FirefoxDriver(profile);
You can use Selenium WebDriverJS
var WebDriver = require('selenium-webdriver');
var driver = new WebDriver.Builder().withCapabilities(
WebDriver.Capabilities.firefox()
).build();
driver.get('url');
Getting error:
FAILED CONFIGURATION: #BeforeMethod setUp
org.openqa.selenium.WebDriverException: The path to the driver
executable must be set by the webdriver.chrome.driver system property;
for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html
My code :
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
+ "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On the above code chromedriver it self is not getting invoked.
Then i tried with code:
ChromeDriverService chromeService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
.usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On executing above code the executable is launched but chrome is not invoked. It throws the same error. Code is working fine for firefox. Any help please?
Download the relevant Chrome driver as per your system(32-bit/64-bit), from here . Try setting the property of ChromeDriver first, like this:
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Then use this code:-
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);
If there is no need of using "RemoteWebDriver", you can code just use this below :
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
Try below :
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");
driver = new ChromeDriver();
driver.get("www.google.com");
Put chrome driver in properties folder.
public void chrome(){
System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/GoogleChrome"); //Chrome
driver = new ChromeDriver();
driver.get(baseUrl);
System.out.println(driver.getTitle());
driver.close();
driver.quit();
}
running this method throw an error "[4032:519:0701/155158:ERROR:process_singleton_mac.cc(106)] Unable to obtain profile lock."
Download the ChromeDriver.exe from [http://code.google.com/p/selenium/downloads/list] then add the system property as,
System.setProperty("webdriver.chrome.driver", "...\chromedriver.exe");
driver = new ChromeDriver();
Path of chromedriver.exe file should be proper.
hope it will helpful for you.
You need to set the path ChromeDriver before creating ChromeDriver instance
System.setProperty("webdriver.chrome.driver", "/Users/test/ChromeDriverMac/chromedriver");
driver = new ChromeDriver();
driver.get("https://www.google.com");
Download chromedriver from below location
https://code.google.com/p/chromedriver/downloads/list