Selenium with java issue using webdriver.firefox.marionette - java

package main_files;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class main_downloader {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.firefox.marionette", "C:\\Users\\ahmed\\Desktop\\JavaPackage\\packages\\webdriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.wait(1);
driver.get("https://www.google.com/");
driver.quit();
}
}
idk why, but for some reason this not working !, when I try to run it it just opens a Firefox window and do nothing !, even the search bar "which is supposed to recognize that I'm using a bot and change it's theme" is not doing that, could anyone tell me what's the exact problem please?!, Thx

The current implementation of Selenium no more uses the key webdriver.firefox.marionette and instead of that you need to use webdriver.gecko.driver. Effectively, you need to replace the line:
System.setProperty("webdriver.firefox.marionette", "C:\\Users\\ahmed\\Desktop\\JavaPackage\\packages\\webdriver\\geckodriver.exe");
with:
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ahmed\\Desktop\\JavaPackage\\packages\\webdriver\\geckodriver.exe");
References
You can find a couple of relevent detailed discussions in:
UnreachableBrowserException Caused by: java.lang.NullPointerException when “webdriver.firefox.marionette” is used
Difference between webdriver.firefox.marionette & webdriver.gecko.driver

Related

Error :"java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property" is displayed

Following is my code snippet :
public class FindAllElementsFromTable {
WebDriver driver;
#BeforeClass
public void beforeClass(){
System.setProperty("Webdriver.chrome.driver","C:\\Selenium Drivers\\chromedriver.exe");
driver = new ChromeDriver();
}
and some tests after this.
When executed,getting above exception.
I tried with forward slash i.e. "C:/Selenium Drivers/chromedriver.exe" as well, but it makes no difference. I checked other answers, but I haven't made any of those mistakes like initialising the chromedriver twice/wrong place/setting property after WebDriver initialization/wrong driver name etc.
Can you help me understanding the exact issue?
You have a typo in your setProperty line.
It should be webdriver not Webdriver
System.setProperty("webdriver.chrome.driver","C:\\Selenium Drivers\\chromedriver.exe");

Eclipse - Error: Could not find or load main class seleniumpackage.Sample

package path hi friends,
am sorry to post this question as i know this question was already answered many times but the reason i post is am new to java, selenium & eclipse.
have browsed through the answers and infact tried some of the solutions but still facing the below error message.
Error: Could not find or load main class seleniumpackage.Sample
below is my simple program in which i try to open chrome browser and access facebook home page.
package seleniumpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Sample {
public WebDriver good;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:/Users/hp/Downloads/Chrome/chromedriver.exe");
WebDriver good = new ChromeDriver();
good.get("https://www.facebook.com/");
}
}
have added chrome browser, selenium client, referenced libraries jar files etc but still facing the error.
please help.

The path to the driver executable must be set by the webdriver.gecko.driver issue in selenium webdriver

I'm trying to run the following sample snippet
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
//System.out.println("My new program");
}
}
When I run this code, getting the following error.
The path to the driver executable must be set by the webdriver.gecko.driver system property;
Firefox version is 48.0
Could anyone please help me to fix this issue.
If you are using windows follow the steps:
Right click my computer and select properties.
Click advanced settings->Environment variables.
Under System variable there should be variable named Path.
By the end of the path variable value add semi colon and then add specify your jecko driver's path. Example(C:\Jeckodriver).
Now compile the code. If it still throws exception then downgrade Firefox to 47.0.1.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test
{
public static WebDriver driver;
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver","Browser path.exe");
driver = new FirefoxDriver();
driver.get("http://www.google.com");
//System.out.println("My new program");
}
}
Download Gecko driver and extract to any folder. Specify gecko driver's path in path variable.

How can I execute Selenide in Chrome using ChromeDriver

I started using selenide (selenium wrapper api) and must say its a great tool but my only issue is its lack of documentation or usage examples online yet.
Any idea how to run your application coded in selenide in google-Chrome. I am using eclipse as IDE. I have added an environment variable "browser" with value chrome in my run configuration but when I run it picks up firefox.
My stack is
JDBC
Java
Selenide
Try this
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
System.setProperty("selenide.browser", "Chrome");
open("http://google.com");
You can find some documentation here.
The below code will help you launch the Chrome Browser with Selenide, and not with the selenium. It means you don't have to issue a close or quit command at the end of the iteration.
import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.*;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.By;
import com.codeborne.selenide.junit.ScreenShooter;
public class SimpleDateFormatClass {
#Rule
public ScreenShooter takeScreenshotSelenide = ScreenShooter.failedTests().succeededTests();
#Test
public void checkGoogleSearchResultsReturnValidResultNumberAndText() {
System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver_2");
//Doesn't matter chrome or Chrome as this is case insensitive.
System.setProperty("selenide.browser", "Chrome");
open("http://google.com");
$(By.name("q")).setValue("Selenide").pressEnter();
// assure there are 10 results in the page
// static import shortcut, place the cursor on the method and press
// ctrl+shift+m/ cmd+shift+m
// $ -> driver.findElement, $$ -> driver.findElements
$$(".iris li.g").shouldHave(size(10));
$(".iris li.g").shouldHave(text("Selenide World!"));
}
}
This should help you even if you are running from the command prompt/ terminal, but if you want to exclusively pass on the Chrome from cmd you can use the "browser" parameter as below
-Dselenide.browser=chrome
You need to tell Selenide what browser to use. That can be done using Configuration properties:
import com.codeborne.selenide.Configuration;
public class Tests {
#Before
public void setBrowser() {
Configuration.browser = "chrome";
}
Remember: your webdriver should be placed on the standard path. For unix/linux it is: /usr/local/bin;
If your webdriver is located on a different path or renamed -- you need to set a system property with right path to the webdriver. For example:
Windows:
System.setProperty("webdriver.chrome.driver", "C:\\Program files\\chromedriver.exe");
Linux\Unix:
System.setProperty("webdriver.chrome.driver","/usr/share/chromedriver");
Make sure that your unix / linux chromedriver is executable. After this, you should have a fully working example (in my case, chromedriver is renamed and has version information):
import com.codeborne.selenide.*;
import org.openqa.selenium.*;
import org.junit.*;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;
import static com.codeborne.selenide.WebDriverRunner.getWebDriver;
public class TestClass {
#Before
public void setBrowser(){
Configuration.browser = "chrome";
Configuration.browserSize = "1920x1080";
Configuration.holdBrowserOpen = true;
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver_2.33");
}
#Test
public void gotoGoogle(){
open("https://www.google.com");
WebElement searchBox = $(By.xpath("//input[#id='lst-ib']"));
$(searchBox).shouldBe(Condition.visible).setValue("How can I execute Selenide in Chrome using ChromeDriver").pressEnter();
WebElement firstResultLink = $(By.xpath("(//div[#class='rc']//a)[1]"));
$(firstResultLink).click();
System.out.println(getWebDriver().getCurrentUrl());
}
}
Another way is to use this command line switch with Maven:
mvn test -P chrome
It requires the Maven profiles in the pom.xml file such as are seen here:
https://github.com/selenide-examples/google
You can use System.setProperty("selenide.browser", "chrome"); for running in the chrome browser. If the same test you need to perform in safari just change the chrome to safari.
Eg:
System.setProperty("selenide.browser", "safari"); open("http://idemo.bspb.ru/");

NoClassDefFoundError error while using Selenium with java

I am new to Selenium and I am trying to access google.co.in. My code is
public static void main(String[] args) {
String baseUrl = "https://www.google.co.in/";
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
}
But I am getting an error which says Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
and I have also written two import statements after loading the appropriate jar file
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
I am new to both selenium and java..So please help..
You must add this library:
selenium-server-standalone-version.jar
and
selenium-java-version.jar
download here: Selenium Downloads

Categories