public class Prog1 {
public static void main(String[] args) {
System.setProperty("WebDriver.chrome.driver", "D:\\Users\\sh\\workspace\\Java2020\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver1.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("Hello world");
You need to replace this line; don't use upper case "Webdriver.chrome.driver"
System.setProperty("webdriver.chrome.driver", "C:/drivders/chromedriver.exe");
And also change this driver1 to use driver
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Time out exception driver object should be driver instead of driver1
Related
While using selenium with java, WebdriverManager is not running and the below code is giving null pointer exception. I have returned the driver at end of class.
I have one ask whether should I keep the Webdriver driver as static or not.
import io.github.bonigarcia.wdm.WebDriverManager;
public class Browserselector {
public WebDriver driver;
public static Properties prop;
public WebDriver initializeDriver() throws IOException {
{
String browserName = "firefox";
System.out.println(browserName);
if (browserName.contains("Chrome")) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if (browserName.contains("IE")) {
WebDriverManager.iedriver().setup();
driver = new InternetExplorerDriver();
} else if (browserName.contains("FireFox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
} else if (browserName.contains("EDGE")) {
WebDriverManager.edgedriver().setup();
driver = new EdgeDriver();
}
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("google.com");
return driver;
}
}
Thanks for your help in advance.
you are trying to start "firefox" - but the if condition checks for "Firefox", if you want to use it like that change the following condition
browserName.contains("FireFox")
into
browserName.equalsIgnoreCase("FireFox")
I recommend you to change the nested if with a "switch" it's more readable and easy to follow/understand
Also, don't use a URL without specifying the protocol
driver.get("https://www.google.com");
This is my code and requirement is that, need to open URL in same local chrome path. Is it possible??
public class Test{
public static void main(String args[]){
System.setProperty("webdriver.chrome.driver","C://Program Files (x86)//Google//Chrome//Application//chrome.exe");
WebDriver d= new ChromeDriver(); ;
String baseurl = "http://www.facebook.com/";
d.get(baseurl);
}
}
System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Downloads\\chromedriver83\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseurl = "http://www.facebook.com/";
driver.get(baseurl);
Check the path of chromedriver.exe carefully from your machine.
For Windows users:
System.setProperty("webdriver.chrome.driver","C:\\Users\\user\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");
For MAC users:
System.setProperty("webdriver.chrome.driver","//Users//apple//Downloads//chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");
I'm trying to browse with Selenium using a proxy but it fails and show my public IP instead
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\driverChrome.exe");
ChromeOptions option = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("200.111.182.6:443");
option.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new ChromeDriver(option);
driver.get("https://whatismyipaddress.com");
driver.manage().window().maximize();
}
As per the Java Docs setCapability() method from MutableCapabilities is defined as:
setCapability
public void setCapability(java.lang.String key, java.lang.Object value)
So instead of setCapability(CapabilityType.PROXY, proxy) you have to use setCapability("proxy", proxy);. So effectively your code block will be:
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\driverChrome.exe");
ChromeOptions option = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("200.111.182.6:443");
option.setCapability("proxy", proxy);
WebDriver driver = new ChromeDriver(option);
driver.get("https://whatismyipaddress.com");
driver.manage().window().maximize();
}
tl; dr
Capabilities & ChromeOptions
The following code solved my problem
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\driverChrome.exe");
ChromeOptions option = new ChromeOptions();
option.addArguments("--proxy-server=http://51.38.22.57:8522");
WebDriver driver = new ChromeDriver(option);
driver.get("https://whatismyipaddress.com");
driver.manage().window().maximize();
}
I'm using Firefox 45.8.0 version and I tried below code to open Firefox browser but i'm getting error that: "The path to the driver executable must be set by the webdriver.gecko.driver system property".
Please sagest me how to set the path.
Note:gecko driver will work for above firefox version 48.
package First;
import org.openqa.selenium.firefox.FirefoxDriver;
public class City {
public static void main(String[] args) {
// TODO Auto-generated method stub
FirefoxDriver c1=new FirefoxDriver();
c1.get("http://google.com");
}
}
Try this below code.
In your code you were not provide gecko driver path. You can download gecko driver from this link
public class City {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get("http://google.com");
}
}
ChromeDriver driver = new ChromeDriver();
ChromeOptions options=new ChromeOptions();
options.addArguments("chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm/index.html");
driver = new ChromeDriver(options);
Tried using the above code.
You can open extension page using below code :
public class sample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "yourpath/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("chrome://extensions/");
}
}
If you want to open plugin page then user below code :
public class sample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "yourpath/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://chrome.google.com/webstore/search/postman?hl=en-US");
}
}
Note : if you have not downloaded "chromedriver" yet , then please download from HERE