Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appium, WebDriver

Tags:

I am new to Appium. I try to execute my selenium script in mobile using Appium. But I got an error like below

org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {ELEMENT=0.5768692365381867-1}

Code I am using is as below :-

AppiumDriver d;
    @BeforeClass
    public void setUp() throws Exception
    {
        //Set Capabilities
        DesiredCapabilities caps=new DesiredCapabilities();
        caps.setCapability("deviceName", "Celkon A35K Remote");
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "4.4.2");
        caps.setCapability("browserName", "Browser");

        d = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
        d.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
        d.manage().timeouts().pageLoadTimeout(120,TimeUnit.SECONDS);
    }
@Test
public void testFBLogin() throws Exception
{
    //Load web page
    d.get("https://www.facebook.com/");
    //Enter user name
    d.findElementByName("email").sendKeys("Appium");
    //Enter password
    d.findElementByName("pass").sendKeys("Appium");
    //Click on Login
    d.findElementByName("login").click();
    Thread.sleep(10000);
}
@AfterClass
public void tearDown()
{
    //Close browser
    d.quit();
}`script:
like image 745
Sam m Avatar asked Sep 05 '17 12:09

Sam m


1 Answers

below code will work for you , better to test on real device. the only change i have done is "caps.setCapability("browserName", "Chrome");"

static AppiumDriver d;
@BeforeClass
public static void setUp() throws Exception
{
    //Set Capabilities
    DesiredCapabilities caps=new DesiredCapabilities();
    caps.setCapability("deviceName", "Celkon A35K Remote");
    caps.setCapability("platformName", "Android");
    caps.setCapability("platformVersion", "6");
    caps.setCapability("browserName", "Chrome");

    d = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);
    d.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    d.manage().timeouts().pageLoadTimeout(120,TimeUnit.SECONDS);
}
@Test
public void testFBLogin() throws Exception
{
    //Load web page
    d.get("https://www.facebook.com/");
    //Enter user name
    d.findElementByName("email").sendKeys("Appium");
    //Enter password
    d.findElementByName("pass").sendKeys("Appium");
    //Click on Login
    d.findElementByName("login").click();
    Thread.sleep(10000);
}
@AfterClass
public static void tearDown()
{
    //Close browser
    d.quit();
}
like image 102
JC . Avatar answered Oct 11 '22 13:10

JC .