0

I have got id associated with the element, but when tried locating this using findElement(By.id()) it doesn't work.

Also, I had gone through few blogs with the same question as given here, but I saw the resource-id in there was prefixed with packagename and :id. In my case, these aren't associated. Screenshot for the element details is below : enter image description here

I have used the below code to locate the element by id.

 - driver.findElement(By.id("loginHome"));
 - driver.findElement(By.id("com.packagename:id/loginHome"));
 - driver.findElement(By.id("android:id/loginHome"));
 - driver.findElement(By.xpath(//*[@id='loginHome']));

But none of the above code snippets worked. Can someone please help me get through with this. Thanks in Advance.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
harshaarchak
  • 1
  • 1
  • 3
  • are you getting `NoSuchElementException` for all of the tried method? also could you give this a try `driver.findElement(By.name(".Login"));` – Naman Feb 18 '16 at 06:16
  • Yes, I'm getting NoSuchElementException. Tried with the driver.findElement(By.name(".Login")); but again same error. This is because the dot (.) seen before Login isn't actually a dot but it's an unified character and hence couldn't proceed further with this. – harshaarchak Feb 18 '16 at 08:18

4 Answers4

0

Not exactly answering your question, but providing an alternative method for you to complete the test.

I follow this link https://github.com/appium/appium-dot-app and it works.

You don't need to code everything. The application provides some easy ways to record your clicks and gestures.

For example, when I click something, it will print out the script automatically. wd.find_element_by_xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[1]").click()

And you just need to choose your favorite programming language and save it after testing is done.

One thing that I have to point out is that the swipe function is corrupted. Use the following code to perform swipe gestures

wd.swipe(421, 424, 70, 424, 500)
VoidExplorer
  • 220
  • 1
  • 5
  • Hi, I'm using Appium on Windows and it doesn't print anything when you click or tap on any element. However, I came up with custom xpath as you had mentioned and it works fine. Here is the code: driver.findElement(By.xpath("//android.webkit.WebView/descendant::android.widget.Button[@index=4]")); But this is not what I'm looking for because in few cases it's really impossible to navigate all the way down to the element using absolute path and is not feasible as well. Hence wanted to try with id's as I had shown in the above snippet, but this isn't helping me locate the elements on the screen. – harshaarchak Feb 18 '16 at 08:08
  • I'm using Mac to perform those tests, but i remember they provide Inspector / Recorder for both platforms. https://github.com/appium/appium-dot-app/blob/master/README-files/images/inspector.png . This may be better cause you don't need to code those xpath. Their length are quite long :/ – VoidExplorer Feb 18 '16 at 08:17
  • Unfortunately, the recorder and added features for Inspector on Mac aren't available on Windows version! :( – harshaarchak Feb 18 '16 at 08:31
0

You can try other options as well. Try this:

//add some wait command before the element
Thread.sleep(2000);
driver.findElementsByXPath("//*[@class='android.widget.Button' and @index='4']");
Gaurav
  • 1,332
  • 11
  • 22
0

Try adding explicit sleep for page to load before clicking usind ID.

anuja jain
  • 1,367
  • 13
  • 19
0

First try to wait for the particular element

MobileElement expelement=(MobileElement) (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.Button[@index='4']")));

Then try to do the click(or the activity you suppose to do)

driver.findElement(By.xpath("//android.widget.Button[@index='4']")).click();
Daz
  • 13
  • 5