Click Facebook login button which is native :
wd.findElement(By.id("com.hathy.fblogin:id/login_button")).click();
Switch to webview context :
//here we getting the list of context
Set<String> contextHandles = wd.getContextHandles();
for (String s : contextHandles) {
System.out.println("Context : " + s);
//if context contains webview then set the webview context
if (s.contains("WEBVIEW")) {
wd.context(s);
}
}
Do Facebook Login Flow in webview :
wd.findElement(By.xpath()).sendKeys("//input[@name='email']""<your_emailid>");
wd"//input[@name='pass']"".findElement(By.xpath()).sendKeys(<your_password>"); // test password
wd.findElement(By.xpath("//button[@name='login']")).click();
WebDriverWait driverWait = new WebDriverWait(wd, 10);
driverWait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@name='__CONFIRM__']"))); // waiting for the element to be clickable
System.out.println(wd.getPageSource()); // get the page source
wd.findElement(By.pathx("//button[@name='__CONFIRM__']")).click(); // this step login process is done.
Come back to Native view :
// here i need to get the context again
Set<String> contextHandles2 = wd.getContextHandles();
for (String s : contextHandles2) {
System.out.println("Context : " + s);
if (s.contains("NATIVE_APP")) {
wd.context(s);
}
}
Youtube video : https://www.youtube.com/analytics?o=U#dt=nt,fe=17092,fr=lw-001,fs=17065;fc=0,fcr=0,fi=v-AcBzbhQgDis,r=realtime,rsc=2