0

I am new to Selendroid and was wondering if someone could help me with this. I am just trying to run a test to make sure it works. Here is my code:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import io.selendroid.common.SelendroidCapabilities;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.util.List;
import java.util.Set;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        WebDriver driver = new WebDriver() {
            @Override
            public void get(String s) {

            }

            @Override
            public String getCurrentUrl() {
                return null;
            }

            @Override
            public String getTitle() {
                return null;
            }

            @Override
            public List<WebElement> findElements(By by) {
                return null;
            }

            @Override
            public WebElement findElement(By by) {
                return null;
            }

            @Override
            public String getPageSource() {
                return null;
            }

            @Override
            public void close() {

            }

            @Override
            public void quit() {

            }

            @Override
            public Set<String> getWindowHandles() {
                return null;
            }

            @Override
            public String getWindowHandle() {
                return null;
            }

            @Override
            public TargetLocator switchTo() {
                return null;
            }

            @Override
            public Navigation navigate() {
                return null;
            }

            @Override
            public Options manage() {
                return null;
            }
        };
        driver.get("https://finance.yahoo.com/quote/TSLA/history?p=TSLA");
        String s = driver.findElement(By.id("search-button")).getText();
        Log.d("Test: ", s);

    }
}

But this is the error I get:

java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String org.openqa.selenium.WebElement.getText()' on a null object reference
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)

I would eventually like to use Selendroid to login to a website and click, but first I have to get this to work. Please help me.

LUKER
  • 540
  • 1
  • 5
  • 23

1 Answers1

1

Creation of WebDriver should be as follow

SelendroidCapabilities capa = new SelendroidCapabilities("io.selendroid.testapp:0.17.0");

WebDriver driver = new SelendroidDriver(capa);

You are creating an anonymous class for WebDriver which has method implementations return null values only, that is why you are getting NPE.

Sandeep Singh
  • 745
  • 4
  • 20