getting Module format not recognized error in eclipse - selenium-webdriver

I have written a selenium script,while creating project it is asking for create module if i don't create this module, directly create project run the script means will get this error."Error occurred during initialization of boot layer
java.lang.module.FindException: Module format not recognized: E:\selenuim\chromedriver_win32\chromedriver.exe
//This is my script//
public class LoginDemo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","E:\\chromedriver.exe");
WebDriver driver =new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Login to an application
driver.get("http://aesportal.azurewebsites.net/");
driver.findElement(By.name("email")).sendKeys("demo");
driver.findElement(By.name("password")).sendKeys("demo");
driver.findElement(By.xpath("//Button[#type='submit'")).click();
}
}

Related

Running Selenium-java automation within gitpod.io

New to SO & test automation & selenium. I got introduced to gitpod while attempting https://www.lambdatest.com/certifications/.
I'm stuck trying to run the below simple code snippet in side Gitpod.
package project.maven.selenium;
import org.openqa.selenium.WebDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class WebDriverManagerDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = WebDriverManager.chromedriver().create();
// Navigate to the demoqa website
driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");
Thread.sleep(3000);
driver.quit();
}
}
Couldn't find a way pass the error below,
Exception in thread "main" io.github.bonigarcia.wdm.config.WebDriverManagerException: There was an error creating WebDriver object for Chrome at io.github.bonigarcia.wdm.WebDriverManager.instantiateDriver(WebDriverManager.java:1775) at io.github.bonigarcia.wdm.WebDriverManager.create(WebDriverManager.java:425) at project.maven.selenium.WebDriverManagerDemo.main(WebDriverManagerDemo.java:9) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Can someone please point out what I'm doing wrong here?
Researched hours but Selenium on Gitpod is not much of a topic, read the getting started guide with Gitpod too, to find a resolution to my problem but no luck before posting here.
Below line of code is incorrect:
WebDriver driver = WebDriverManager.chromedriver().create();
Try the below code:
public static void main(String[] args) throws InterruptedException {
// below line is used to setup chromedriver using WDM
WebDriverManager.chromedriver().setup();
//initialize the driver object
WebDriver driver = new ChromeDriver();
// Navigate to the demoqa website
driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");
Thread.sleep(3000);
driver.quit();
}

org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService

I am trying to run a test on Remote Machine for selenium Grid and it gives me expection erro
Expection
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
Here is my code
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
String nodeURL;
String baseURL;
System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.19.1-win64\\geckodriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.BINARY,new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe").getAbsolutePath());
WebDriver driver = new RemoteWebDriver(new URL("http://10.132.48.16:5566/wd/hub"),capabilities );
driver.get("http://google.com");
System.out.println(driver.getTitle());

seleniumerror while executing below code

I little help here will be appreciated.I am simply trying to open a site using selenium and here is the code. Getting java.lang.IllegalStateException error.
package pkg1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
public class training1 {
/**
* #param args
*/
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
System.out.println("Welcome to Selenium");
driver.get("https://in.yahoo.com/");
}
}
----- Error -----
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
at pkg1.training1.main(training1.java:14)
You must set path of the chromedriver.exe before calling new ChromeDriver()
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
System.out.println("Welcome to Selenium");
driver.get("https://in.yahoo.com/");
}

Exception in thread "main" java.lang.Error:Unresolved compilation problems: working with selenium

I am a begineer in selenium and trying my own after installation of eclipse, java, selenium, TestNg and started writing the below code.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
at Mypackage.MyClass.main(MyClass.java:8)
package Mypackage;
public class MyClass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://google.com";
String expectedTitle = "Welcome: Hello";
String actualTitle = "";
driver.get(baseUrl);
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)) {
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
driver.close();
}
}
you need to add selenium webdriver jar files to the project
right click on project-->goto build path-->configure build path-->click on "Add external jars"-->add selenium jar files from your local machine-->click ok-->now mouseover on WebDriver in your code-->click "import webdriver"--now run your code-->you will get rid of the exception.

Safari browser not launch on real device using appium

I was trying to launch safari browser on real device(iPhone 4) using appium. but it is giving following error.
Unable to install [/var/folders/7_/fz8kyhyn2g97s1m9zylk50xc0000gq/T/11545-10782-1dp1wfm/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app] to device with id [fdaxxx76].
Error [Error: Command failed: /bin/sh -c /Applications/Appium.app/Contents/Resources/node_modules/appium/build/fruitstrap/fruitstrap install --id fda51be7184f865f02de4f4c6cb8fff760964e76 --bundle "/var/folders/7_/fz8kyhyn2g97s1m9zylk50xc0000gq/T/11545-10782-1dp1wfm/submodules/SafariLauncher/build/Release-iphoneos/SafariLauncher.app"
Below is my sample code:
DesiredCapabilities cap = new DesiredCapabilities();
private static WebDriver driver;
#BeforeTest
public void prep() throws MalformedURLException {
System.out.println("Script started");
cap.setCapability("platformName", "iOS");
cap.setCapability("platformVersion", "8.3");
cap.setCapability("deviceName", "iPhone4");
cap.setCapability("udid", "fda51be7184f865f02de4f4c6cb8fff760964e76");
cap.setCapability("browserName", "Safari");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
#Test
public void googleTest() {
System.out.println("main method");
driver.get("http://google.com");
}
You need to create a provisioning profile to deploy it to a real device.
Follow instructions here.
Hope this helps,
Liam

Resources