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

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!

Related

Selenium4: "The method newWindow(WindowType) is undefined for the Type WebDriver.TargetLocator"

I'm trying to play with the Selenium 4 features in eclipse with java but can't seem to get them to work, which i'm assuming must be my mistake in configuration, so I'd appreciate if anyone can explain where i'm going wrong and how I can correct it?
Code below: I get an error warning on the last line (containing the newWindow() method) and the error message is as per the Title of this post.
I've downloaded the selenium-java-4.0.0-alpha-4 from here https://selenium-release.storage.googleapis.com/index.html?path=4.0-alpha4/
i've created a new eclipse java project, and unzipped and included all of the jar files in my java build path, but it doesn't seem to recognise / or be able to find the newWindow() method
package practice;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.withTagName;
import org.openqa.selenium.By;
public class Sel4alpha4 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\me\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.switchTo().newWindow(WindowType.TAB); // this line has the error
}
}
There might be two problems:
1) Incorrect Import- You should import the following:
org.openqa.selenium.WindowType;
2) Issue with the version you are using. Try to upgrade the selenium version.
Version:
selenium 4.0.0-beta-4
Please try to download the updated jar from the below link:
https://www.selenium.dev/downloads/
or
https://selenium-release.storage.googleapis.com/index.html?path=4.0-beta-4/

Selenium Web Driver Mozilla Only Open

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.

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.

Programmatically install Android app from java program (Runtime.getRunTime().exec(adb.exe install app_package_name)

I am writing a automation program where from Java code, Android app has to be installed and later uninstalled.
The sample snippet is:
Process p = Runtime.getRunTime().exec(adb.exe install -s device_id apks\app_package_name);
I used right values for above app_package_name, does not have .apk file extension and device_id respectively.
This does not install the app on device. The app is user app.
Can you please let me know if I have to make any settings in app (in manifest file) or elsewhere (or in Java program) to make this work.
You dont need to use adb when you perform it programatically,
Specifying the apk path in your machine and the package name will by default push the app to the device and will land in the launcher activity/home screen ogf your app, try using the below code,
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class installApp{
static AndroidDriver<WebElement> driver;
private static DesiredCapabilities capa = null;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
capa = new DesiredCapabilities();
capa.setCapability("automationName","Appium");
capa.setCapability("platformName","Android");
capa.setCapability("deviceName","device name");
capa.setCapability("udid", "ur device udid");
capa.setCapability("platformVersion","5.1");
capa.setCapability("newCommandTimeout","30");
capa.setCapability("appPackage", "com.your app's package name");
capa.setCapability("appActivity", "com.your app's launcher activity");
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capa);
}
}

"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