selenium configuration ChromeDriver works but ChromeOptions not found - java

I have just configured Selenium for Java on Eclipse on a new PC (have configured without issue for a number of times in the past) and can run a sample code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AutoLogin {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C://pathtodrive//chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Open Register
driver.get("https://google.com");
// Maximize browser
driver.manage().window().maximize();
}
}
The above code works perfectly and could see google.com open in the browser window. Now I wanted to change some of the default options like default download directory, certificate check etc. I could see the ChromeOptions.class under imported client-combined-3.141.59.jar
But when I write
import org.openqa.selenium.chrome.ChromeOptions;
the eclipse shows error
the import org.openqa.selenium.chrome.ChromeOptions cannot be resolved
please advise what could be wrong? and which configuration I am missing
os: windows 10 64 bit eclipse: Helios Service Release 1
(Build id: 20100917-0705 ) 32 bit java: jre1.8.0_261 32 bit

In addition to the specified import, the driver must be properly initialized. In the code below, it works. That is, first we specify the options, then we use this variable to create a web driver instance.
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito", "headless", "disable-gpu", "window-size=1366,768", "ignore-certificate-errors");
newWebDriver = new ChromeDriver(options);
And of course the corresponding import.
import org.openqa.selenium.chrome.ChromeOptions;

Related

Launching of GC when Selenium basic program is run

I am running the following code in Eclipse but my Google Chrome is not launching.
The configurations are:
Eclipse IDE for Java Developers
Version: 2019-12 (4.14.0)
Have taken latest versions for GC driver.
The same code and config is working for another laptop but not on mine. Have re-installed the application several time.
All the libraries available on internet have also been imported.
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.*;
public class FirstTestCase {
public static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.firefox.driver", "C:\\Users\\WC-Parul\\Downloads\\geckodriver-v0.26.0-win64.zip");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
// Launch the Online Store Website
// driver.get("http://www.shop.demoqa.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.Store.Demoqa.com");
// Close the driver
// driver.quit();
}
}
you say Chrome? you are not use
FirefoxDriver driver = new FirefoxDriver();
you should
WebDriver driver = new ChromeDriver();
and you should download chromedriver.exe
Hope it helps you
If not, please take a screenshot "Java Build Path"
Extract C:\\Users\\WC-Parul\\Downloads\\geckodriver-v0.26.0-win64.zip and provide geckodriver.exe path
Something like
System.setProperty("webdriver.firefox.driver", "C:\\Users\\WC-Parul\\Downloads\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
Make sure your downloaded correct version of geckodriver
If you want to run the code on Chrome browser then download compatible chromedriver.exe from here as per your chrome browser version and use below code:
System.setProperty("webdriver.chrome.driver", "drive_path\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");

Error occurred when use gecko in selenium

i am new to selenium automation and i have follwed the instruction of the web site and i have use gecko driver but it shows message as below.i have follow few web articals but i didnt get the solution.i am using firefox 60.0.2 (64-bit) , Selenium 3.12 and gecko driver 20.1 .
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
here is my code
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class userLogin{
public static void main(String[] args){
System.setProperty("webdriver.gecko.driver ","E:\\\\Selenium\\\\geckodriver-v0.21.0-win64\\\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
}
Edit: reformat code
Replace it
System.setProperty("webdriver.gecko.driver","E:\\\\Selenium\\\\geckodriver-v0.21.0-win64\\\\geckodriver.exe");
it has extra space...

How do I get started with Selenium?

I'm trying to begin using Selenium. I have downloaded the Selenium Stand Alone Server, Selenium for JAVA, and GeckoDriver. I added all of the .jar files from the Stand Alone Server and Selenium for JAVA to my buildpath in Eclipse. When I run my program, I get the follwing error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
FirefoxOptions cannot be resolved to a type
FirefoxOptions cannot be resolved to a type
at check.Selenium_Basic.main(Selenium_Basic.java:14)
My code is below:
package check;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Selenium_Basic {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\User1\\Documents\\geckodriver-v0.16.1-win32\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //This is the location where you have installed Firefox on your machine
FirefoxDriver driver = new FirefoxDriver(options);
driver.get("http://www.google.com");
}
}
Do you guys know why this doesn't work? Is there a good step by step guide that will allow me to start using this? I have looked at many guides but I can't figure out what I've done incorrectly.
The code looks good. You are missing an import statement for FirefoxOptions. You can add the below line to your code with other import statements & your code should work.
import org.openqa.selenium.firefox.FirefoxOptions;
Also, you don't need to use Selenium StandAlone Server. Selenium Java alone with GeckoDriver would work fine. Make sure that you are using Selenium 3.4, as its compatible with Gecko 16.
You can also check this link for complete setup related steps -
Selenium 3.4 – Complete Guide to the latest Selenium WebDriver

Selenium in java eclipse linux

I have the following error
and here is my code
import org.openqa.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class io {
/**
* #param args
*/
public static void main(String[] args) {
WebDriver driver=new ChromeDriver();
}
}
I mention that this error appear only when a do "new ChromeDriver()" .If i let without that it don't do that and i don't know what i need to do to solve it.Please help.
EDIT: After i dowloaded the chrome driver when i execute the program it works fine but when i am debugging it suspend.Why this happens?
You have to set the System property before creating an instance of the chrome driver. Download chromedriver in your machine and add below line to your code before initializing the chromedriver.
System.setProperty("webdriver.chrome.driver","<path to chromedriver>");
Hope it helps.
Take a look at my project, https://github.com/codezombies/easytest. One of the methods on my project makes chrome driver initialization happens before the tests run ( actually upon driver type selection ). With that said, i embedded the 3 types of chrome driver on different OS, and it should work as well on linux.

How do I setup the InternetExplorerDriver so it works

I am using WebDriver and I have downloaded the InternetExplorerDriver and was wondering what I do with it after it is downloaded?
This says to put the driver in my path. Not really certain what exactly they are talking about there.
Has anyone used this and if so could you provide detailed steps on how to set it up so it will work?
I am getting the following error:
The path to the driver executable must be set by the
webdriver.ie.driver system property
I downloaded the executables for IE and the Chrome driver. Where do I set it at?
Unpack it and place somewhere you can find it. In my example, I will assume you will place it to C:\Selenium\iexploredriver.exe
Then you have to set it up in the system. Here is the Java code pasted from my Selenium project:
File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
Basically, you have to set this property before you initialize driver
Reference:
Driver executable must be set by the webdriver.ie.driver system property
If you are using RemoteDriver things are different. From http://element34.ca/blog/iedriverserver-webdriver-and-python :
You will need to start the server using a line like
java -jar selenium-server-standalone-2.26.0.jar -Dwebdriver.ie.driver=C:\Temp\IEDriverServer.exe
I found that if the IEDriverServer.exe was in C:\Windows\System32\ or its subfolders, it couldn't be found automatically (even though System32 was in the %PATH%) or explicitly using the -D flag.
Another way to resolve this problem is:
Let's assume:
path_to_driver_directory = C:\Work\drivers\
driver = IEDriverServer.exe
When getting messsage about path you can always add path_to_driver_directory containing driver to the PATH environment variable.
Check:
http://java.com/en/download/help/path.xml
Then simply check in cmd window if driver is available - just run cmd in any location and type name of driver.
If everything works fine then you get:
C:\Users\A>IEDriverServer.exe
Started InternetExplorerDriver server (32-bit)
2.28.0.0
Listening on port 5555
Thats it.
This is just to help somebody in future.
When we initiate InternetExplorerDriver() instance in a java project it uses IEDriver.exe (downloaded by individuals) which tries to extract temporary files in user's TEMP folder when it's not in path then ur busted.
Safest way is to provide your own extract path as shown below
System.setProperty("webdriver.ie.driver.extractpath", "F:\\Study\\");
System.setProperty("webdriver.ie.driver", "F:\\Study\\IEDriverServer.exe");
System.setProperty("webdriver.ie.logfile", "F:\\Study\\IEDriverServer.log");
InternetExplorerDriver d = new InternetExplorerDriver();
d.get("http://www.google.com");
d.quit();
public class NavigateUsingAllBrowsers {
public static void main(String[] args) {
WebDriver driverFF= new FirefoxDriver();
driverFF.navigate().to("http://www.firefox.com");
File file =new File("C:/Users/mkv/workspace/ServerDrivers/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driverIE=new InternetExplorerDriver();
driverIE.navigate().to("http://www.msn.com");
// Download Chrome Driver from http://code.google.com/p/chromedriver/downloads/list
file =new File("C:/Users/mkv/workspace/ServerDrivers/ChromeDriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driverChrome=new ChromeDriver();
driverChrome.navigate().to("http://www.chrome.com");
}
}
Basically you need to download the IEDriverServer.exe from Selenium HQ website without executing anything just remmeber the location where you want it
and then put the code on Eclipse like this
System.setProperty("webdriver.ie.driver", "C:\\Users\\juan.torres\\Desktop\\QA stuff\\IEDriverServer_Win32_2.32.3\\IEDriverServer.exe");
WebDriver driver= new InternetExplorerDriver();
driver.navigate().to("http://www.youtube.com/");
for the path use double slash //
ok have fun !!
Here is the exact solution, which worked in my case:
On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
System.setProperty("webdriver.ie.driver","C:\\Users\\ssin22\\Downloads\\IEDriverServer_x64_2.48.0\\IEDriverServer.exe");
package Testing;
import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class LaunchIE {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver","C:\\Users\\ssin22\\Downloads\\IEDriverServer_x64_2.48.0\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.get("http://google.com");
}
}
using System.Text;
...
..
static void Main(String[] args){
var driver = new InternetExplorerDriver(#"C:\Users\PathToTheFolderContainingIEDriver.exe");
driver.Navigate().GoToUrl("https://www.google.com/");
Console.Read();
}
You need not include the .exe file. The path to the folder containing the .exe worked for me
WebDriverManager allows to automate the management of the binary drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium WebDriver.
Link: https://github.com/bonigarcia/webdrivermanager
you can use something link this: WebDriverManager.iedriver().setup();
add the following dependency for Maven:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>x.x.x</version>
<scope>test</scope>
</dependency>
or see: https://www.toolsqa.com/selenium-webdriver/webdrivermanager/

Categories

Resources