Hi!
I am struggling with an issue of not being able to find an element inside android.webkit.WebView. In a nutshell, it is a ReactNative application that in a few places uses WebView content coming directly from the network. One such a place is user group management and the page in Android SDK uiautomator look like that
Since there are no resource id’s available, I though that the easiest way to find the input field (EditText) would be to start from the preceding text element “Employee number”. However, I could not do that with the code:
import com.microsoft.appcenter.appium.EnhancedAndroidDriver;
import com.microsoft.appcenter.appium.Factory;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public WebDriverWait wait;
public EnhancedAndroidDriver<MobileElement> driver;
@Before
public void createAppiumDriverAndLogin() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 7913);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
capabilities.setCapability(MobileCapabilityType.SUPPORTS_LOCATION_CONTEXT, "true");
capabilities.setCapability("autoGrantPermissions", "true");
URL url = new URL("http://localhost:4723/wd/hub");
driver = Factory.createAndroidDriver(url, capabilities);
wait = new WebDriverWait(driver, 30, 500);
}
@Test
public void updateGroupInfoTest() {
/*
Series of steps navigating through application menu to reach the desired page
*/
driver.findElementByXPath("//android.view.View[@text=\"Employee number\"]/following-sibling::android.widget.EditText").setValue("12345");
}
When running the tests, I am getting “noSuchElement”. Trying to simplify the XPath first to
"//android.view.View[@text=\"Employee number\"]"
and then even to
"//*[@text=\"Employee number\"]
provides the Appium logs like that:
2018-07-03 16:58:49:608 - info: [HTTP] --> POST /wd/hub/session/0ba1d11a-0b58-49f2-8b0d-54cb8ecdf6e2/element {"using":"xpath","value":"//*[@text=\"Employee number\"]"}
2018-07-03 16:58:49:610 - info: [debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//*[@text=\"Employee number\"]","0ba1d11a-0b58-49f2-8b0d-54cb8ecdf6e2"]
2018-07-03 16:58:49:611 - info: [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-07-03 16:58:49:612 - info: [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-07-03 16:58:49:612 - info: [debug] [BaseDriver] Waiting up to 0 ms for condition
2018-07-03 16:58:49:613 - info: [debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/e2d5fbaf-ee77-4501-ad91-1907349d3b5e/element] with body: {"strategy":"xpath","selector":"//*[@text=\"Employee number\"]","context":"","multiple":false}
2018-07-03 16:58:49:683 - info: [HTTP] <-- POST /wd/hub/session/0ba1d11a-0b58-49f2-8b0d-54cb8ecdf6e2/element 500 74 ms - 164
What am I possibly doing wrong?
I am using:
- Appium v1.7.1
- JDK 1.8.0.152
- io.appium:java-client:5.0.4
- org.seleniumhq.selenium:*:3.6.0