Selenium Web Driver Mozilla Only Open - java

I started to learn SeleniumWeb driver with Java and I write some code like this :
package firstPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class firstScript {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http//:www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("mysql excel 2013");
element.submit();
}
}
If I run this code, mozilla only start, It is not contiune. I want to it to "google" and search "mysql excell 2013". How can I do?

I am using the selenium-server-standalone-3.5.3.jar in which this code is not working but when I changed jar from 3.5.3 to 2.44.0 then Its working fine.
Its opening the firefox and search the "mysql excel 2013" and got the results of it.
So you need to change the selenium version or need to change the browser from firefox to chrome.

Related

A beginner : How to identify errors in selenium webdriver [duplicate]

This question already has answers here:
java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests
(5 answers)
Closed 3 years ago.
Question is:
1) In my simple program how do I identify errors in each line before run it?
2) I placed my program here, while running I am getting many errors. How can I resolve them?
Program:
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Myclass {
public static void main(String[] args) {
System.out.println("Chrome is selected");
System.setProperty("webdriver.chrome.driver","C:\\ProgramFiles\\Chrome65.0.3325.146\\googlechromeportable.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
//XPath for Email Field
driver.findElement(By.xpath("//*[#id='login']")).sendKeys("xxx#gmail.com");
//XPath for Password Field
//driver.findElement(By.xpath("//*[#id='pass']")).sendKeys("xxxxxxx");
driver.findElement(By.xpath("//*[#id=\"u_0_a\"]")).click();
}
}
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type
By cannot be resolved`enter code here`
By cannot be resolved
at newpackage.Myclass.main(Myclass.java:16)
You need to specify the driver location , by mistake you gave the browser.exe path so kindly modify your code as below . My chromedriverexe in Jar_files folder and you may need to download it and place it there . I advise you to refer a blog or a video prior to scripting so that you can get more clear idea.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ExecutionbasedOnTReachabilityOfSite {
WebDriver driver;
#BeforeClass()
public void setUp() throws IOException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\Jar_files\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
// To start Chrome in Maximized browser window
options.addArguments("start-maximized");
// To remove Chrome is being controlled by automated test software
options.addArguments("disable-infobars");
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
It is because you have not added selenium-server-standalone-3.141.59.jar as dependency in build path.
Download JAR from below path:
https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar
Right click on Project Folder > Build Path > Configure Build Path > Select & Add downloaded external JAR
All compile time errors that you are getting will be resolved.

Unable to get URL in mozilla in selenium webdriver

I am using Mozilla 51.0.1 and Eclipse Lunar 3.0.1. When I am trying to run my code I am not able to get URL in the browser, it just opens.
package SessionPack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SessionCalss {
public static void main(String arg[])
{
System.out.println("String");
WebDriver driver;
System.setProperty("webdriver.gecko.driver", "C:\\New folder\\geckodriver.exe");
driver=new FirefoxDriver();
driver.get("www.gooogle.com");
}
}
Your request is wrong in two places:
You write extra character "o" - gooogle
You have to added https:// before URL-adress - https://www.google.com
After fix this code will be work.
You have to specify http:// or https:// specifically; you have to change your URL string from:
www.gooogle.com to https://www.gooogle.com

Drag and drop not working in Selenium 3.0

I am trying the below code to test drag and drop in Selenium 3.0 and find that code is not working, meaning that it's not showing any error and also not providing expected result.
I have tried the same code in selenium 2.53 and it's working . Kindly someone review my code for the same and let me know if I missed something.
Selenium 3.0
Browser : Mozilla 2.52
package dynamicXpath;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class refermeprobI {
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.gecko.driver", "D:\\Drivers\\geckodriver.exe");
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("https://the-internet.herokuapp.com/drag_and_drop");
Actions act = new Actions(driver);
WebElement src = driver.findElement(By.xpath("//*[#id='column-a']"));
WebElement dst = driver.findElement(By.xpath("//*[#id='column-b']"));
act.dragAndDrop(src, dst).build().perform();
System.out.println(driver.findElement(By.xpath("//*[#id='column-b']/header")).getText());
}
}
I've checked your code. Everything is fine except if you use Selenium 3.0.0 then need to set Desired Capabilities. I've also checked your code with Selenium latest 3.4. If you use Selenium 3.4 then you don't need to set Desired Capabilities. I used Firefox 52.
I hope that this info will help you to understand the problem you have encountered.
Thanks
You can also try following:
act.clickAndHold(src).moveToElement(dst).release(src).build().perform();
This works in certain scenarios where dragAndDrop() doesn't.

The 'import org.openqa.selenium.android.AndroidDriver' cannot be resolved

I am trying to automate an android application,
I have taken following code,
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.android.AndroidDriver;
public class LaunchElGiftoAndroid {
public static void main(String args[])throws Exception
{
AndroidDriver ad=new AndroidDriver();
System.out.println("Started");
ad.get("http://www.gmail.com");
System.out.println("Application Title"+ ad.getTitle());
Thread.sleep(2000);
ad.findElement(By.name("Email")).sendKeys("testing");
ad.findElement(By.name("Passwd")).sendKeys("type password");
ad.findElement(By.name("signIn")).click();
System.out.println("Opened");
ad.close();
}
}
I have installed the Web driver apk properly.
i was getting problem with the following import statement.
import org.openqa.selenium.android.AndroidDriver;
I believe you using the old AndroidDriver.
You should be using Selendroid in that case.
http://selendroid.io/mobileWeb.html
If you check this webpage. Selenium recommends you to switch to Selendroid as it has more features and options. You can even do automation inside an app!

"WebDriver cannot be resolved to a type" error in Android WebDriver java code

I have prepared the environment for test automation of Android Application using eclipse. I have followed the instruction from the below site:
https://code.google.com/p/selenium/wiki/AndroidDriver#Setup_the_Environment
I have copied the following code from the above website as below:
import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;
public class OneTest extends TestCase {
public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
But error as "WebDriver cannot be resolved to a type" was found at the following line:
WebDriver driver = new AndroidDriver();
Note: I have added "selenium-server-standalone-2.33.0.jar" to Java Build Path
Only one import statement is needed to fix the error. import the following and that's it:
import org.openqa.selenium.WebDriver;
You need to properly install the android server available here http://code.google.com/p/selenium/downloads/list .
Follow this tutorial http://code.google.com/p/selenium/wiki/AndroidDriver#Install_the_Android_SDK
regarding how to install the android web driver.
Add - import org.openqa.selenium.WebElement;

Categories

Resources