What package to import to use UiSelector?

1,295 views
Skip to first unread message

Andrew Dinh

unread,
Jul 25, 2014, 8:45:28 PM7/25/14
to appium-...@googlegroups.com
I looked at the example test files for java-client.  There are the packages one of the tests imported to use UiSelector:
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import io.appium.java_client.remote.MobileCapabilityType;
import java.io.File;
import java.net.URL;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
 
I checked that all of these are imported in my test file.  Yet, when I ran the test, UiSelector was not recognized as a symbol.
 
So I googled around and tried to import
 
import com.android.uiautomator.core.UiSelector;
 
But then I got an error that package com.android.uiautomator.core does not exist. 
 
Can anyone help please?  Thank you!

Isaac Murchie

unread,
Jul 25, 2014, 10:40:45 PM7/25/14
to Andrew Dinh, appium-...@googlegroups.com


--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Andrew Dinh

unread,
Jul 25, 2014, 11:07:57 PM7/25/14
to appium-...@googlegroups.com, trieu...@gmail.com
Hi Isaac,

I was trying to find and click on a Cancel button like this.

driver.findElementByAndroidUIAutomator(new UiSelector().text("Cancel")).click();

Isaac Murchie

unread,
Jul 25, 2014, 11:34:18 PM7/25/14
to Andrew Dinh, appium-...@googlegroups.com
The argument to the findElement call is a string that will be interpreted as Java. Try putting it in quotes. 
--

Andrew Dinh

unread,
Jul 25, 2014, 11:42:01 PM7/25/14
to appium-...@googlegroups.com, trieu...@gmail.com
You mean like this?  driver.findElementByAndroidUIAutomator("new UiSelector().text("Cancel")").click();
 
That didn't work either.
 
 

Isaac Murchie

unread,
Jul 26, 2014, 12:04:32 AM7/26/14
to Andrew Dinh, appium-...@googlegroups.com
Define "didn't work". Is there anything in the logs?

See the examples in the doc I pointed to above for working examples. 


On Friday, July 25, 2014, Andrew Dinh <trieu...@gmail.com> wrote:
You mean like this?  driver.findElementByAndroidUIAutomator("new UiSelector().text("Cancel")").click();
 
That didn't work either.
 
 

--

Andrew Dinh

unread,
Jul 26, 2014, 11:21:18 AM7/26/14
to appium-...@googlegroups.com, trieu...@gmail.com
Thank you for your help so far Isaac.

This is what I meant by didn't work:

[ERROR] C:\Appium2\Appium\Cam2\src\test\java\androidPages\CamPreview_Single.java:[40,45] error: cannot find symbol
[ERROR]   symbol:   class UiSelector
  location: class CamPreview_Single

That's why in the original message, I was asking what package to import.  Maybe my pom file is incorrect?  Here are my pom dependencies:

   <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>LATEST</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>1.5.0</version>
</dependency>
    </dependencies>

bootstrap online

unread,
Jul 26, 2014, 12:16:17 PM7/26/14
to Andrew Dinh, appium-...@googlegroups.com
The UiSelector class is never used by client code, it's server only.
The client sends a string of Java to the server. There's nothing to
import.

Andrew Dinh

unread,
Jul 27, 2014, 11:46:44 AM7/27/14
to appium-...@googlegroups.com, trieu...@gmail.com
Actually, problem is now solved.  It was a syntax error on my part.  Before I was doing this:

driver.findElementByAndroidUIAutomator("new UiSelector().text("Cancel")").click();

But I should have done this

driver.findElementByAndroidUIAutomator("new UiSelector().text('Cancel')").click();

Now I got another issue.  But that's for another post.  Thanks Matt and Isaac for your help!

Andrew


On Friday, July 25, 2014 8:34:18 PM UTC-7, Isaac Murchie wrote:
The argument to the findElement call is a string that will be interpreted as Java. Try putting it in quotes. 

On Friday, July 25, 2014, Andrew Dinh <trieu...@gmail.com> wrote:
Hi Isaac,

I was trying to find and click on a Cancel button like this.

driver.findElementByAndroidUIAutomator(new UiSelector().text("Cancel")).click();

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discuss+unsubscribe@googlegroups.com.

bootstrap online

unread,
Jul 27, 2014, 12:00:33 PM7/27/14
to Andrew Dinh, appium-...@googlegroups.com
If you backslash escape the quotes, that should work as well.

driver.findElementByAndroidUIAutomator("new
UiSelector().text(\"Cancel\")").click();

>>> email to appium-discus...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/appium-discuss.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> http://appium.io
> ---
> You received this message because you are subscribed to the Google Groups
> "Appium-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to appium-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages