I have an issue clicking or tapping an item using Appium-Eclipse-TestNG framework in android emulator
New to Appium any help is appreciated
My code:
public void testmethod() {
List<MobileElement> buttonlist = driver.findElements(By.xpath("//android.app.Dialog//android.view.View//android.widget.Button"));
buttonlist.forEach(webElement -> log.info(webElement.getAttribute("name")));
for (MobileElement button : buttonlist) {
System.out.println(".................button name=>" + button.getAttribute("name") + "<");
if ("Send Email ".equals(button.getAttribute("name"))) {
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
button.click();
break;
}
}
}
C# for loop prints all the items in the list whereas using java it prints only one. Am I doing something wrong? I see it quickly clicks on top of android screen and closes without clicking the actual element.
java
add a comment |
New to Appium any help is appreciated
My code:
public void testmethod() {
List<MobileElement> buttonlist = driver.findElements(By.xpath("//android.app.Dialog//android.view.View//android.widget.Button"));
buttonlist.forEach(webElement -> log.info(webElement.getAttribute("name")));
for (MobileElement button : buttonlist) {
System.out.println(".................button name=>" + button.getAttribute("name") + "<");
if ("Send Email ".equals(button.getAttribute("name"))) {
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
button.click();
break;
}
}
}
C# for loop prints all the items in the list whereas using java it prints only one. Am I doing something wrong? I see it quickly clicks on top of android screen and closes without clicking the actual element.
java
add a comment |
New to Appium any help is appreciated
My code:
public void testmethod() {
List<MobileElement> buttonlist = driver.findElements(By.xpath("//android.app.Dialog//android.view.View//android.widget.Button"));
buttonlist.forEach(webElement -> log.info(webElement.getAttribute("name")));
for (MobileElement button : buttonlist) {
System.out.println(".................button name=>" + button.getAttribute("name") + "<");
if ("Send Email ".equals(button.getAttribute("name"))) {
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
button.click();
break;
}
}
}
C# for loop prints all the items in the list whereas using java it prints only one. Am I doing something wrong? I see it quickly clicks on top of android screen and closes without clicking the actual element.
java
New to Appium any help is appreciated
My code:
public void testmethod() {
List<MobileElement> buttonlist = driver.findElements(By.xpath("//android.app.Dialog//android.view.View//android.widget.Button"));
buttonlist.forEach(webElement -> log.info(webElement.getAttribute("name")));
for (MobileElement button : buttonlist) {
System.out.println(".................button name=>" + button.getAttribute("name") + "<");
if ("Send Email ".equals(button.getAttribute("name"))) {
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
button.click();
break;
}
}
}
C# for loop prints all the items in the list whereas using java it prints only one. Am I doing something wrong? I see it quickly clicks on top of android screen and closes without clicking the actual element.
java
java
edited Nov 27 '18 at 17:36
Panee S
asked Nov 14 '18 at 4:44
Panee SPanee S
225
225
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You must use the unique element ID to access button. You can access the element using id, resource-id, accessibility id and xpath.
xpath is not recommended
If you don't have unique id in your app elements, you can ask your developer to put it in their code.
You can use Appium Desktop Inspector to inspect the element. After knowing the exact element, you can click the button as follow:
MobileElement button= driver.findElementByAccessibilityId("your element's accessibility id");
button.click();
//or
MobileElement button= driver.findElementById("your element's id or resource id");
button.click();
You can get or id, resource-id or accessibility-id from appium desktop inspector
If you want to use xpath for your button, get it from the appium desktop inspector and use it as:
MobileElement button= driver.findElement(By.xpath("your element's xpath shown in appium"));
button.click();
Thanks for your suggestion, will give a try
– Panee S
Nov 14 '18 at 16:47
add a comment |
There are few issues I can see in your code.
First, you don't need to call implicit wait in the for loop. Use it once right after initializing driver with time out of 1 min or more.
Second, you have added extra space in your if condition, it should be as,
if ("Send Email".contains (button.getAttribute("name"))) {
button.click();
break;
}
Third, is more of a suggestion. Instead of click, use AndroidTouchAction classes tap method like,
AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (e)))
.perform ();
Thanks for the solution. The names have extra space in it. Also, I tried using trim and equalsIgnoreCase which did not work either. Since it doesn't has any id's nothing has worked including accessibilityId which is //android.widget.Button[@content-desc="Send Email "]
– Panee S
Nov 26 '18 at 17:00
I have earlier tried touch actions which doesn't work too. The tap method throws compilation errors, can you please correct it?
– Panee S
Nov 26 '18 at 18:43
If tap is throwing compilation error that means you are using old Appium Java client which you need to upgrade to 6.1.0 and use Java jdk 1.8. Once this is done then you won't get compilation errors.
– Wasiq Bhamla
Nov 26 '18 at 18:56
Thank you, will give a try
– Panee S
Nov 26 '18 at 23:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293322%2fi-have-an-issue-clicking-or-tapping-an-item-using-appium-eclipse-testng-framewor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You must use the unique element ID to access button. You can access the element using id, resource-id, accessibility id and xpath.
xpath is not recommended
If you don't have unique id in your app elements, you can ask your developer to put it in their code.
You can use Appium Desktop Inspector to inspect the element. After knowing the exact element, you can click the button as follow:
MobileElement button= driver.findElementByAccessibilityId("your element's accessibility id");
button.click();
//or
MobileElement button= driver.findElementById("your element's id or resource id");
button.click();
You can get or id, resource-id or accessibility-id from appium desktop inspector
If you want to use xpath for your button, get it from the appium desktop inspector and use it as:
MobileElement button= driver.findElement(By.xpath("your element's xpath shown in appium"));
button.click();
Thanks for your suggestion, will give a try
– Panee S
Nov 14 '18 at 16:47
add a comment |
You must use the unique element ID to access button. You can access the element using id, resource-id, accessibility id and xpath.
xpath is not recommended
If you don't have unique id in your app elements, you can ask your developer to put it in their code.
You can use Appium Desktop Inspector to inspect the element. After knowing the exact element, you can click the button as follow:
MobileElement button= driver.findElementByAccessibilityId("your element's accessibility id");
button.click();
//or
MobileElement button= driver.findElementById("your element's id or resource id");
button.click();
You can get or id, resource-id or accessibility-id from appium desktop inspector
If you want to use xpath for your button, get it from the appium desktop inspector and use it as:
MobileElement button= driver.findElement(By.xpath("your element's xpath shown in appium"));
button.click();
Thanks for your suggestion, will give a try
– Panee S
Nov 14 '18 at 16:47
add a comment |
You must use the unique element ID to access button. You can access the element using id, resource-id, accessibility id and xpath.
xpath is not recommended
If you don't have unique id in your app elements, you can ask your developer to put it in their code.
You can use Appium Desktop Inspector to inspect the element. After knowing the exact element, you can click the button as follow:
MobileElement button= driver.findElementByAccessibilityId("your element's accessibility id");
button.click();
//or
MobileElement button= driver.findElementById("your element's id or resource id");
button.click();
You can get or id, resource-id or accessibility-id from appium desktop inspector
If you want to use xpath for your button, get it from the appium desktop inspector and use it as:
MobileElement button= driver.findElement(By.xpath("your element's xpath shown in appium"));
button.click();
You must use the unique element ID to access button. You can access the element using id, resource-id, accessibility id and xpath.
xpath is not recommended
If you don't have unique id in your app elements, you can ask your developer to put it in their code.
You can use Appium Desktop Inspector to inspect the element. After knowing the exact element, you can click the button as follow:
MobileElement button= driver.findElementByAccessibilityId("your element's accessibility id");
button.click();
//or
MobileElement button= driver.findElementById("your element's id or resource id");
button.click();
You can get or id, resource-id or accessibility-id from appium desktop inspector
If you want to use xpath for your button, get it from the appium desktop inspector and use it as:
MobileElement button= driver.findElement(By.xpath("your element's xpath shown in appium"));
button.click();
answered Nov 14 '18 at 5:29
Suban DhyakoSuban Dhyako
660317
660317
Thanks for your suggestion, will give a try
– Panee S
Nov 14 '18 at 16:47
add a comment |
Thanks for your suggestion, will give a try
– Panee S
Nov 14 '18 at 16:47
Thanks for your suggestion, will give a try
– Panee S
Nov 14 '18 at 16:47
Thanks for your suggestion, will give a try
– Panee S
Nov 14 '18 at 16:47
add a comment |
There are few issues I can see in your code.
First, you don't need to call implicit wait in the for loop. Use it once right after initializing driver with time out of 1 min or more.
Second, you have added extra space in your if condition, it should be as,
if ("Send Email".contains (button.getAttribute("name"))) {
button.click();
break;
}
Third, is more of a suggestion. Instead of click, use AndroidTouchAction classes tap method like,
AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (e)))
.perform ();
Thanks for the solution. The names have extra space in it. Also, I tried using trim and equalsIgnoreCase which did not work either. Since it doesn't has any id's nothing has worked including accessibilityId which is //android.widget.Button[@content-desc="Send Email "]
– Panee S
Nov 26 '18 at 17:00
I have earlier tried touch actions which doesn't work too. The tap method throws compilation errors, can you please correct it?
– Panee S
Nov 26 '18 at 18:43
If tap is throwing compilation error that means you are using old Appium Java client which you need to upgrade to 6.1.0 and use Java jdk 1.8. Once this is done then you won't get compilation errors.
– Wasiq Bhamla
Nov 26 '18 at 18:56
Thank you, will give a try
– Panee S
Nov 26 '18 at 23:56
add a comment |
There are few issues I can see in your code.
First, you don't need to call implicit wait in the for loop. Use it once right after initializing driver with time out of 1 min or more.
Second, you have added extra space in your if condition, it should be as,
if ("Send Email".contains (button.getAttribute("name"))) {
button.click();
break;
}
Third, is more of a suggestion. Instead of click, use AndroidTouchAction classes tap method like,
AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (e)))
.perform ();
Thanks for the solution. The names have extra space in it. Also, I tried using trim and equalsIgnoreCase which did not work either. Since it doesn't has any id's nothing has worked including accessibilityId which is //android.widget.Button[@content-desc="Send Email "]
– Panee S
Nov 26 '18 at 17:00
I have earlier tried touch actions which doesn't work too. The tap method throws compilation errors, can you please correct it?
– Panee S
Nov 26 '18 at 18:43
If tap is throwing compilation error that means you are using old Appium Java client which you need to upgrade to 6.1.0 and use Java jdk 1.8. Once this is done then you won't get compilation errors.
– Wasiq Bhamla
Nov 26 '18 at 18:56
Thank you, will give a try
– Panee S
Nov 26 '18 at 23:56
add a comment |
There are few issues I can see in your code.
First, you don't need to call implicit wait in the for loop. Use it once right after initializing driver with time out of 1 min or more.
Second, you have added extra space in your if condition, it should be as,
if ("Send Email".contains (button.getAttribute("name"))) {
button.click();
break;
}
Third, is more of a suggestion. Instead of click, use AndroidTouchAction classes tap method like,
AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (e)))
.perform ();
There are few issues I can see in your code.
First, you don't need to call implicit wait in the for loop. Use it once right after initializing driver with time out of 1 min or more.
Second, you have added extra space in your if condition, it should be as,
if ("Send Email".contains (button.getAttribute("name"))) {
button.click();
break;
}
Third, is more of a suggestion. Instead of click, use AndroidTouchAction classes tap method like,
AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (e)))
.perform ();
answered Nov 15 '18 at 6:33
Wasiq BhamlaWasiq Bhamla
691159
691159
Thanks for the solution. The names have extra space in it. Also, I tried using trim and equalsIgnoreCase which did not work either. Since it doesn't has any id's nothing has worked including accessibilityId which is //android.widget.Button[@content-desc="Send Email "]
– Panee S
Nov 26 '18 at 17:00
I have earlier tried touch actions which doesn't work too. The tap method throws compilation errors, can you please correct it?
– Panee S
Nov 26 '18 at 18:43
If tap is throwing compilation error that means you are using old Appium Java client which you need to upgrade to 6.1.0 and use Java jdk 1.8. Once this is done then you won't get compilation errors.
– Wasiq Bhamla
Nov 26 '18 at 18:56
Thank you, will give a try
– Panee S
Nov 26 '18 at 23:56
add a comment |
Thanks for the solution. The names have extra space in it. Also, I tried using trim and equalsIgnoreCase which did not work either. Since it doesn't has any id's nothing has worked including accessibilityId which is //android.widget.Button[@content-desc="Send Email "]
– Panee S
Nov 26 '18 at 17:00
I have earlier tried touch actions which doesn't work too. The tap method throws compilation errors, can you please correct it?
– Panee S
Nov 26 '18 at 18:43
If tap is throwing compilation error that means you are using old Appium Java client which you need to upgrade to 6.1.0 and use Java jdk 1.8. Once this is done then you won't get compilation errors.
– Wasiq Bhamla
Nov 26 '18 at 18:56
Thank you, will give a try
– Panee S
Nov 26 '18 at 23:56
Thanks for the solution. The names have extra space in it. Also, I tried using trim and equalsIgnoreCase which did not work either. Since it doesn't has any id's nothing has worked including accessibilityId which is //android.widget.Button[@content-desc="Send Email "]
– Panee S
Nov 26 '18 at 17:00
Thanks for the solution. The names have extra space in it. Also, I tried using trim and equalsIgnoreCase which did not work either. Since it doesn't has any id's nothing has worked including accessibilityId which is //android.widget.Button[@content-desc="Send Email "]
– Panee S
Nov 26 '18 at 17:00
I have earlier tried touch actions which doesn't work too. The tap method throws compilation errors, can you please correct it?
– Panee S
Nov 26 '18 at 18:43
I have earlier tried touch actions which doesn't work too. The tap method throws compilation errors, can you please correct it?
– Panee S
Nov 26 '18 at 18:43
If tap is throwing compilation error that means you are using old Appium Java client which you need to upgrade to 6.1.0 and use Java jdk 1.8. Once this is done then you won't get compilation errors.
– Wasiq Bhamla
Nov 26 '18 at 18:56
If tap is throwing compilation error that means you are using old Appium Java client which you need to upgrade to 6.1.0 and use Java jdk 1.8. Once this is done then you won't get compilation errors.
– Wasiq Bhamla
Nov 26 '18 at 18:56
Thank you, will give a try
– Panee S
Nov 26 '18 at 23:56
Thank you, will give a try
– Panee S
Nov 26 '18 at 23:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293322%2fi-have-an-issue-clicking-or-tapping-an-item-using-appium-eclipse-testng-framewor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown