In the Below image, when i am selecting Gallery, a pop up is shown. I am trying to select Photos, but it is always fails to find element.
I tried both solutions it failed.
- driver.findElement(By.name(“Photos”)).click(); - FAILS
- driver.findElement(By.xpath("//android.widget.TextView[@text=‘Photos’]")).click(); - FAILS
Hi tapangkumar,
If you are selecting a Image button on a Native Application, please correct the Step 1 with below and try again:
-> driver.findElement(By.linkText(“Photos”)).click();
or
-> driver.findElement(By.partialLinkText(“Photos”)).click();
Hope this helps…
1 Like
No Success Lohit. It does not find the element.
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“partial link text”,“selector”:“Photos”}
try with resource id “android:id/text1”
Hey…I found solution for the issue. The actual issue is after switching the context from Native to Web , i was not swtiching the context to Native. So after switching the context to native, i am able to select the button. Below is the procedure.
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains(“NATIVE_APP”)){
Thread.sleep(10000);
driver.context(contextName);
}
}
driver.findElement(By.xpath("//android.widget.TextView[@text='Photos']")).click();