0

Trying to locate the element in mobile app.

` public class Ovex { private static AndroidDriver driver;

public static void main(String[] args) throws MalformedURLException, InterruptedException {


     DesiredCapabilities capabilities = new DesiredCapabilities();
     capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
     capabilities.setCapability("deviceName", "Glaxy S7 edge");
     capabilities.setCapability("platformVersion", "8.0.0");
     capabilities.setCapability("platformName", "Android");
     capabilities.setCapability("appPackage", "com.ovex_rn");
     capabilities.setCapability("appActivity", "com.ovex_rn.MainActivity");



     driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
     driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
     driver.findElement(By.xpath("//android.widget.TextView[contains(text(), 'Markets']")).click();

    // driver.quit();

} ` 

Here is path from UI AUtomator Click link to view Xpath from UIAutomator

At this line debugger shows an error and display these error messages:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'
System info: host: 'DESKTOP-45IINVJ', ip: '192.168.210.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.ovex_rn, deviceScreenSize=1440x2560, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=ce051605b4cc832c04, platform=LINUX, deviceUDID=ce051605b4cc832c04, appActivity=com.ovex_rn.MainActivity, desired={appPackage=com.ovex_rn, appActivity=com.ovex_rn.MainActivity, platformVersion=8.0.0, platformName=Android, deviceName=Glaxy S7 edge}, platformVersion=8.0.0, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, javascriptEnabled=true, deviceModel=SM-G935F, platformName=Android, deviceManufacturer=samsung}]

 Session ID: 5b780d61-b329-4a8c-8614-928084365cf8
*** Element info: {Using=xpath, value=//TextView[contains(text(),'Markets')]}
Muneeb Akhtar
  • 87
  • 3
  • 11
  • Does the XPath get the correct element when you try it manually? And are you trying to click just after the page has been loaded? – StevieBruce Jan 30 '19 at 16:30
  • Can you attach the locator hierarchy for the given element, you be easier to find the xpath of the element ? – Sameer Arora Jan 30 '19 at 16:32
  • Appium does not use tag elements like you are attempting to use when the target is a native app. TextView should almost certain be `android.widget.TextView` – Bill Hileman Jan 30 '19 at 16:37
  • I should add that you should show more of your code, as I can't tell if you're even using the correct webdriver, etc. – Bill Hileman Jan 30 '19 at 16:39
  • @BillHileman I have updated the code. – Muneeb Akhtar Jan 31 '19 at 08:33
  • @SameerArora I have attached the UIAutomator Screenshot in "Click link to view Xpath from UIAutomator" link – Muneeb Akhtar Jan 31 '19 at 08:45
  • @MuneebAkhtar i have posted the answer, please check that. Let me know if it works. – Sameer Arora Jan 31 '19 at 08:52
  • @SameerArora i tried it in try catch ` try { driver.findElement(By.xpath("//android.widget.TextView[@text='Markets']")).click(); } catch(Exception e) { System.out.println("Hello World"); }` here its doesn't show any error in console that's mean code is correct. . but executed catch block. Find element path didn't executed. – Muneeb Akhtar Jan 31 '19 at 09:10
  • Can you check it by using contains ? and if that also doesn't work can you check that the element you are operating on is not in an iframe ? because then you need to switch to the iframe and then click on it. – Sameer Arora Jan 31 '19 at 09:19
  • @SameerArora it doesn't work with contain also. . Could you please tell me how you are saying with iframe. . I don't have idea about iframe. – Muneeb Akhtar Jan 31 '19 at 09:48
  • Can you tell me the app name and the page from which you are clicking this element, i will install it on my phone and then will help you – Sameer Arora Jan 31 '19 at 10:02
  • @SameerArora Actually it's an apk file. . where could i send you apk file? – Muneeb Akhtar Jan 31 '19 at 11:07
  • @MuneebAkhtar Send it to sameer98733@gmail.com – Sameer Arora Jan 31 '19 at 11:13
  • You don't show your driver declaration, only its initialization. Make sure you define it as `AppiumDriver` and alter the initialization to include empty ankle brackets after AppiumDriver – Bill Hileman Jan 31 '19 at 12:28
  • Possible duplicate of [Appium: "An element could not be located on the page using the given search parameters" error](https://stackoverflow.com/questions/25180309/appium-an-element-could-not-be-located-on-the-page-using-the-given-search-para) – Saif Siddiqui Aug 15 '19 at 10:38

1 Answers1

1

Please change the xpath to driver.findElement(By.xpath("//android.widget.TextView[@text='Markets']"); and if you want to use contains then use xpath like this: driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'Markets')]");

You have used text() in xpath which works for web/mweb automation, in android app, @text works instead of text()

Sameer Arora
  • 4,439
  • 3
  • 10
  • 20