Unable to find Webview on Real Android Device but it is working when I ran it on emulator
Step To Open WebView: Open App and click on Message Icon (Green Circle Icon) above the Notification tab.
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("automationName", "uiAutomator2");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "9");
cap.setCapability("deviceName", "OPPO F11 Pro");
cap.setCapability("appPackage", "com.traveltriangle.traveller");
cap.setCapability("appActivity", "com.traveltriangle.traveller.MainActivity");
Thread.sleep(3000);
driver.findElement(MobileBy.AccessibilityId("CustomFAB_470_2")).click();
Thread.sleep(4000);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")) {
driver.context(contextName);
}
}
// System.out.println(driver.getPageSource());
waitForElementPresent(By.xpath("(//a[@class='rsc-os-option-element sc-bxivhb PUXvG'])[1]"), 30);
driver.findElement(By.xpath("(//a[@class='rsc-os-option-element sc-bxivhb PUXvG'])[1]")).click();
waitForElementPresent(By.xpath("(//a[@class='rsc-os-option-element sc-bxivhb PUXvG'])[1]"), 30);
driver.findElement(By.xpath("(//a[@class='rsc-os-option-element sc-bxivhb PUXvG'])[1]")).click();
waitForElementPresent(By.xpath("//input[@placeholder='Type your destination...']"), 30);
driver.findElement(By.xpath("//input[@placeholder='Type your destination...']")).sendKeys("cool");
}
public static void waitForElementPresent(final By by, int timeOutInSeconds) {
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
// TODO Auto-generated method stub
return d.findElement(by).isDisplayed();
}
});
}