Repository: appium/java-client
Issue: Update page object features. Server node 1.5.x

These things should be done:
- mark  _name_ parameter _Decrecated_ as _By.name_ selector is not supported by native app automation
- _By.id_ selector should be used by default (native content) when not any selector strategy defined.
- _org.openqa.selenium.InvalidSelectorException_ should be handled.


Changed files:
src/main/java/io/appium/java_client/pagefactory/AndroidFindBy.java, src/test/java/io/appium/java_client/pagefactory_tests/iOSPageObjectTest.java, src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java, src/main/java/io/appium/java_client/pagefactory/ThrowableUtil.java, src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java

diff --git a/src/main/java/io/appium/java_client/pagefactory/AndroidFindBy.java b/src/main/java/io/appium/java_client/pagefactory/AndroidFindBy.java
index 1dd3e485..5569fe83 100644
--- a/src/main/java/io/appium/java_client/pagefactory/AndroidFindBy.java
+++ b/src/main/java/io/appium/java_client/pagefactory/AndroidFindBy.java
@@ -35,7 +35,11 @@ public @interface AndroidFindBy {
 	String uiAutomator() default "";
 	String accessibility()  default "";
 	String id() default "";
-	String name() default "";
+	@Deprecated
+	/**
+	 * By.name selector is not supported by Appium server node since 1.5.x.
+	 * So this option is going to be removed further. Be careful.
+	 */String name() default "";
 	String className() default "";
 	String tagName() default "";
 	String xpath()  default "";
diff --git a/src/main/java/io/appium/java_client/pagefactory/ThrowableUtil.java b/src/main/java/io/appium/java_client/pagefactory/ThrowableUtil.java
index b7c71fe9..bcfb18bf 100644
--- a/src/main/java/io/appium/java_client/pagefactory/ThrowableUtil.java
+++ b/src/main/java/io/appium/java_client/pagefactory/ThrowableUtil.java
@@ -16,6 +16,7 @@
 
 package io.appium.java_client.pagefactory;
 
+import org.openqa.selenium.InvalidSelectorException;
 import org.openqa.selenium.StaleElementReferenceException;
 
 import java.lang.reflect.InvocationTargetException;
@@ -28,7 +29,11 @@ class ThrowableUtil {
             return false;
         }
 
-        if (String.valueOf(e.getMessage()).contains(INVALID_SELECTOR_PATTERN)) {
+        if (InvalidSelectorException.class.isAssignableFrom(e.getClass())) {
+            return true;
+        }
+
+        if (String.valueOf(e.getMessage()).contains(INVALID_SELECTOR_PATTERN) || String.valueOf(e.getMessage()).contains("Locator Strategy \\\\w+ is not supported")) {
             return true;
         }
 
diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java b/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java
index b666df94..6f38ed2a 100644
--- a/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java
+++ b/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java
@@ -35,7 +35,11 @@ public @interface iOSFindBy {
 	String uiAutomator() default "";
 	String accessibility()  default "";
 	String id() default "";
-	String name() default "";
+	@Deprecated
+	/**
+	 * By.name selector is not supported by Appium server node since 1.5.x.
+	 * So this option is going to be removed further. Be careful.
+	 */String name() default "";
 	String className() default "";
 	String tagName() default "";
 	String xpath()  default "";
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java
index b3129e67..fd15db3f 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java
@@ -17,6 +17,7 @@
 package io.appium.java_client.pagefactory_tests;
 
 import io.appium.java_client.android.AndroidDriver;
+import io.appium.java_client.android.AndroidElement;
 import io.appium.java_client.pagefactory.*;
 import io.appium.java_client.remote.AutomationName;
 import io.appium.java_client.remote.MobileCapabilityType;
@@ -37,7 +38,7 @@ import java.util.concurrent.TimeUnit;
 import static org.junit.Assert.*;
 
 public class SelendroidModeTest {
-	private static int SELENDROID_PORT = 9999;
+    private static int SELENDROID_PORT = 9999;
 
     private static WebDriver driver;
     private static AppiumDriverLocalService service;
@@ -63,15 +64,15 @@ public class SelendroidModeTest {
     private WebElement textXpath;
 
     @SelendroidFindBys({
-        @SelendroidFindBy(id = "text1")})
+            @SelendroidFindBy(id = "text1")})
     private WebElement textIds;
 
     @SelendroidFindAll({
-        @SelendroidFindBy(id = "text1")})
+            @SelendroidFindBy(id = "text1")})
     private WebElement textAll;
 
     @SelendroidFindAll({
-        @SelendroidFindBy(id = "text1")})
+            @SelendroidFindBy(id = "text1")})
     private List<WebElement> textsAll;
 
     @SelendroidFindBy(className = "android.widget.TextView")
@@ -79,14 +80,14 @@ public class SelendroidModeTest {
 
     @SelendroidFindBy(tagName = "TextView")
     private WebElement textTag;
-    
+
     @SelendroidFindBy(linkText = "Accessibility")
     private WebElement textLink;
-    
+
     @SelendroidFindBy(partialLinkText = "ccessibilit")
     private WebElement textPartialLink;
 
-	@BeforeClass
+    @BeforeClass
     public static void beforeClass() throws Exception {
         AppiumServiceBuilder builder = new AppiumServiceBuilder().withArgument(GeneralServerFlag.AUTOMATION_NAME, AutomationName.SELENDROID);
         service = builder.build();
@@ -123,8 +124,8 @@ public class SelendroidModeTest {
     public void findByIdElementTest() {
         assertNotEquals(null, textId.getAttribute("text"));
     }
-    
-        @Test
+
+    @Test
     public void findBySelendroidSelectorTest() {
         assertNotEquals(null, textSelendroidId.getAttribute("text"));
     }
@@ -173,15 +174,15 @@ public class SelendroidModeTest {
     public void findByElementByTagTest() {
         assertNotEquals(null, textTag.getAttribute("text"));
     }
-    
+
     @Test
     public void findBySelendroidAnnotationOnlyTest() {
         assertNotEquals(null, textSelendroidId.getAttribute("text"));
     }
-    
+
     @Test
     public void findBySelendroidLinkTextTest() {
         assertEquals("Accessibility", textLink.getText());
 
     }
-}
+}
\\ No newline at end of file
diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/iOSPageObjectTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/iOSPageObjectTest.java
index ac7c04d1..ce83f338 100644
--- a/src/test/java/io/appium/java_client/pagefactory_tests/iOSPageObjectTest.java
+++ b/src/test/java/io/appium/java_client/pagefactory_tests/iOSPageObjectTest.java
@@ -37,9 +37,9 @@ import java.util.List;
 
 public class iOSPageObjectTest {
 
-    private static WebDriver driver;
-    private static AppiumDriverLocalService service;
-    private boolean populated = false;
+	private static WebDriver driver;
+	private static AppiumDriverLocalService service;
+	private boolean populated = false;
 
 	@FindBy(className = "UIAButton")
 	private List<WebElement> uiButtons;
@@ -67,9 +67,9 @@ public class iOSPageObjectTest {
 	private List<RemoteWebElement> remoteElementViews;
 
 	@AndroidFindBys({
-		@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\\"android:id/list\\")"),
-		@AndroidFindBy(className = "android.widget.TextView")
-		})
+			@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\\"android:id/list\\")"),
+			@AndroidFindBy(className = "android.widget.TextView")
+	})
 	private List<WebElement> chainElementViews;
 
 
@@ -92,11 +92,11 @@ public class iOSPageObjectTest {
 	@iOSFindBy(uiAutomator = ".elements()[0]")
 	private MobileElement mobileButton;
 
-    @iOSFindBy(uiAutomator = ".elements()[0]")
-    private TouchableElement touchableButton;
+	@iOSFindBy(uiAutomator = ".elements()[0]")
+	private TouchableElement touchableButton;
 
-    @iOSFindBy(uiAutomator = ".elements()[0]")
-    private List<TouchableElement> touchableButtons;
+	@iOSFindBy(uiAutomator = ".elements()[0]")
+	private List<TouchableElement> touchableButtons;
 
 	@FindBy(className = "UIAButton")
 	private MobileElement mobiletFindBy_Button;
@@ -105,69 +105,70 @@ public class iOSPageObjectTest {
 	private RemoteWebElement remotetextVieW;
 
 	@AndroidFindBys({
-		@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\\"android:id/list\\")"),
-		@AndroidFindBy(className = "android.widget.TextView")
-		})
+			@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\\"android:id/list\\")"),
+			@AndroidFindBy(className = "android.widget.TextView")
+	})
 	private WebElement chainElementView;
-	
+
 	@iOSFindBy(uiAutomator = ".elements()[0]")
 	private IOSElement iosButton;
-	
+
 	@iOSFindBy(uiAutomator = ".elements()[0]")
 	private List<IOSElement> iosButtons;
-	
+
 	@iOSFindAll({
-		@iOSFindBy(xpath = "ComputeSumButton_Test"),
-		@iOSFindBy(name = "ComputeSumButton")	//it is real locator
+			@iOSFindBy(xpath = "ComputeSumButton_Test"),
+			@iOSFindBy(name = "ComputeSumButton")	//it is real locator
 	})
 	private WebElement findAllElement;
-	
+
 	@iOSFindAll({
-		@iOSFindBy(xpath = "ComputeSumButton_Test"),
-		@iOSFindBy(name = "ComputeSumButton")	//it is real locator
+			@iOSFindBy(xpath = "ComputeSumButton_Test"),
+			@iOSFindBy(name = "ComputeSumButton")	//it is real locator
 	})
 	private List<WebElement> findAllElements;
 
-    @AndroidFindBy(className = "android.widget.TextView")
-    @FindBy(css = "e.e1.e2")
-    private List<WebElement> elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;
-
-    @AndroidFindBy(className = "android.widget.TextView")
-    @FindBy(css = "e.e1.e2")
-    private WebElement elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;
-
-
-    @BeforeClass
-    public static void beforeClass() throws Exception {
-        service = AppiumDriverLocalService.buildDefaultService();
-        service.start();
+	@AndroidFindBy(className = "android.widget.TextView")
+	@FindBy(css = "e.e1.e2")
+	private List<WebElement> elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;
 
-        File appDir = new File("src/test/java/io/appium/java_client");
-        File app = new File(appDir, "TestApp.app.zip");
-        DesiredCapabilities capabilities = new DesiredCapabilities();
-        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
-        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.4");
-        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
-        capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
-        driver = new IOSDriver<>(service.getUrl(), capabilities);
-    }
+	@AndroidFindBy(className = "android.widget.TextView")
+	@FindBy(css = "e.e1.e2")
+	private WebElement elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;
+
+
+	@BeforeClass
+	public static void beforeClass() throws Exception {
+		service = AppiumDriverLocalService.buildDefaultService();
+		service.start();
+
+		File appDir = new File("src/test/java/io/appium/java_client");
+		File app = new File(appDir, "TestApp.app.zip");
+		DesiredCapabilities capabilities = new DesiredCapabilities();
+		capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
+		capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
+		capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
+		capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
+		driver = new IOSDriver(service.getUrl(), capabilities);
+	}
 
+	@SuppressWarnings("rawtypes")
 	@Before
 	public void setUp() throws Exception {
-        if (!populated)
-		    PageFactory.initElements(new AppiumFieldDecorator(driver), this);
+		if (!populated)
+			PageFactory.initElements(new AppiumFieldDecorator(driver), this);
 
-        populated = true;
+		populated = true;
 	}
 
-    @AfterClass
-    public static void afterClass() throws Exception {
-        if (driver != null)
-            driver.quit();
+	@AfterClass
+	public static void afterClass() throws Exception {
+		if (driver != null)
+			driver.quit();
 
-        if (service != null)
-            service.stop();
-    }
+		if (service != null)
+			service.stop();
+	}
 
 	@Test
 	public void findByElementsTest() {
@@ -273,7 +274,7 @@ public class iOSPageObjectTest {
 		}
 		Assert.assertNotNull(nsee);
 	}
-	
+
 	@Test
 	public void isIOSElementTest(){
 		Assert.assertNotEquals(null, iosButton.getText());
@@ -294,38 +295,38 @@ public class iOSPageObjectTest {
 		Assert.assertNotEquals(null, findAllElement.getText());
 	}
 
-    @Test
-    public void isTouchAbleElement(){
-        Assert.assertNotEquals(null, touchableButton.getText());
-    }
+	@Test
+	public void isTouchAbleElement(){
+		Assert.assertNotEquals(null, touchableButton.getText());
+	}
 
-    @Test
-    public void areTouchAbleElements(){
-        Assert.assertNotEquals(0, touchableButtons.size());
-    }
+	@Test
+	public void areTouchAbleElements(){
+		Assert.assertNotEquals(0, touchableButtons.size());
+	}
 
-    @Test
-	@SuppressWarnings("unused")
-    public void isTheFieldIOSElement(){
+	@Test
+	public void isTheFieldIOSElement(){
+		@SuppressWarnings("unused")
 		IOSElement iOSElement = (IOSElement) mobileButton; //declared as MobileElement
-        iOSElement = (IOSElement) iosUIAutomatorButton; //declared as WebElement
-        iOSElement = (IOSElement) remotetextVieW;  //declared as RemoteWebElement
-        iOSElement = (IOSElement) touchableButton; //declared as TouchABLEElement
-    }
-
-    @Test
-    public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy(){
-        try {
-            Assert.assertNotEquals(null, elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text"));
-        }
-        catch (NoSuchElementException ignored){
-            return;
-        }
-        throw new RuntimeException(NoSuchElementException.class.getName() + " has been expected.");
-    }
-
-    @Test
-    public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy_List(){
-        Assert.assertEquals(0, elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.size());
-    }
-}
+		iOSElement = (IOSElement) iosUIAutomatorButton; //declared as WebElement
+		iOSElement = (IOSElement) remotetextVieW;  //declared as RemoteWebElement
+		iOSElement = (IOSElement) touchableButton; //declared as TouchABLEElement
+	}
+
+	@Test
+	public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy(){
+		try {
+			Assert.assertNotEquals(null, elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text"));
+		}
+		catch (NoSuchElementException ignored){
+			return;
+		}
+		throw new RuntimeException(NoSuchElementException.class.getName() + " has been expected.");
+	}
+
+	@Test
+	public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy_List(){
+		Assert.assertEquals(0, elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.size());
+	}
+}
\\ No newline at end of file