Unable to click button in mobile web in appium - selenium

After exhaustively searching for this over various forums, I still don't have an answer.
Here are complete details
I'm identifying the element through classname which points to multiple(4) buttons. I'm iterating through buttons and then search for text and when there is a match i click it.
This works fine with selenium webdriver and browsers such as firefox,chrome
Now I'm doing the same thing with appium.
Out of 4 buttons which are identified through classname, the script clicks 2 buttons successfully but for two buttons click happens(i can see the button being clicked) but new page which should be loaded is not loaded. The buttons for which click is not happening are in a footer class and other two are in div class.
Things i have already tried
Actions builder - click(), clickandhold()
Javascript executor
I'm currently trying with touch options, tap and by switching to native view but haven't found any success.
If any has encountered the same, a solution will be appreciated.
I want to avoid xPath because that might change in the page I'm working on, and I want to stress that the script is able to find the button, but is not able to click it properly.

You can filter your locator by using class name and index. Like this:
driver.findElementsByXPath("//*[#class='android.widget.ImageView' and #index='0']");
This xpath won't get change on other devices too.

Could you see: Unable to find an element in Browser of the Android emulator using Appium and C# ?
In case of testing web apps in browser the elements should be located as usual elements on the web page ( not as some classes like android.widget.EditText and android.widget.Button).

Upadting appium java client to 1.5.0 (from 1.3.0) solved the issue. Need to check why!

Related

I cannot Select an Element with the AndroidFindBy

I am fairly new to Appium and i am currently working on UI testing of an application. I want to click an element but it is not visible until you scroll down the page.
I have tried using the command below but it does not work for me
driver.findElement(By.xpath("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("WebView").instance(0))")).click();
You need to replace "By.xpath" with "MobileBy.AndroidUIAutomator".
See Appium's documentation.

Unable to find xpath using Appium desktop

Use case
I need to click on ANSWER button as shown in screen below
What I Tried ?
I used Appium desktop to inspect element , but this Answer button does not seems to be effectively identified by it.
Having little experience in creating XPATH, I tried with diffrent combinations of XPATH
//android.widget.FrameLayout[contains(#text,'ANSWER')]")
//android.widget.ScrollView[contains(#text,'ANSWER')]")
//android.widget.Button[#resource-id='android:id/action0']
android:id/action0
xpath=//*[#text='ANSWER']
But none of them are working!!
Is there anyway of doing it ?

"Cannot locate an element using By.xpath" error in selenium java

I am getting Cannot locate an element using By.xpath error in Selenium using Java(IE11). I am working on a web page created using Adobe AEM(CQ5).
I have tried the following possible solutions but neither of it helped.
Tried to add wait.
Switch to active window.
Tried even on Chrome.
Bring focus on element.
Currently using the absolute path (/html/body/div[4]/header[1]/div[1]/div[2]/div[5]/div[1]/nav/ul[1]/li[3]/a) but also used relative path (.//*[#id='cq-gen188']/nav/ul/li[3]/a).
Also searched whether there is any iframe involved. Unfortunately there was none.
To find the xpath, I have used FirePath plugin in Firefox. When i search for the element using the xpath in Firefox, i am successful. But when i execute the code i get the error.
If you are in the correct IFRAME then you can use
driver.findElement(By.id("cq-gen188"));
Remember that ID is always unique and that's a core assumption for all of the libraries in the authoring UI whether it is from core AEM framework or from custom components.
Your problem may be due to incorrect IFRAME as AEM neatly makes the UI look like a seamless window but there are IFRAME in place to facilitate various authoring navigation experiences.

Not able to click on ionic specific tags in hybrid app using appium

I am trying to automate a hybrid app build in ionic2/cordova and typescript
HTML page somewhat looks like
<ion-input _ng_somename class="header-signin-part">
<input class="header" placeholder="heading" color="abc">
When I am trying to identify element using Xpath I am not able to
//ion-input//input[#class='header']
//input[#placeholder='heading']
I tried various other combinations but in vain. Can anybody tell me why am I struggling to identify elements. is it something in ionic which is stopping the element identification(ionic specific tags for not identifiable in webview)
Steps whih I am doing
Launching the app using appium
Switching the context with driver.Context="WebView_1";(C# way of switching context)
Opening the safari browser and navigating to "localhost:27753" (Note: I have already started the webkit debug proxy on same port)
Identifying the elements
Also, app gets close everytime after some time without I doing anything. It doesn't hold on to webview
I am using only appium(not protractor) for automation
there are multiple ways you can locate this element:
<ion-content class="scroll-content ionic-scroll has-header">
You can try:
xpath: //ion-content[#class='scroll-content ionic-scroll has-header'] (please bear in mind, it looks like there are two space chars between ionic-scroll and has-header)
xpath: //ion-view[#view-title='Home']/ion-content
css selector: ion-content[class='scroll-content ionic-scroll has-header']
css selector: ion-view[view-title='Home'][class='pane']>ion-content

How to click on Toolbar Item with selenium?

Web page contain a button with some text for example "Test". This button actually is a toolbar element. ( class ="tbButton" id="id",text="Test") and redirects to a certain table when press on it.
When try to use the following click methods
selenium.click("id");
selenium.doubleClick("id");
selenium.click("//*[text()='Test'and contains(#class, 'tbButton')] ");
the button does not react
Could enybody show an alternative methods that is able to resolve a problem
It's hard to know exactly what the problem is without knowing more about the actual contents of the page you are testing. Is there an example of the toolbar online somewhere?
With modern interfaces, locating elements with Selenium is not always an exact science. Here are a few suggestions:
With modern interfaces you often find that the DOM is being manipulated, so it is possible that the identifier you are using is no longer valid by the time you get to your click(). Use Firebug to check that you have the correct element.
Often it helps to click on the parent of the element, such as a div or the parent table cell. Again, use FireBug, to try some other elements near your toolbar button. Alternatively, Firebug sometimes reveals that the element contains other elements. You might have more luck changing the target to a contained element instead.
Sometimes you have to play around with some of the alternative actions. For instance, some controls respond to a mouseDown() followed by a mouseUp(), but not to a click(). Again you can often get hints from looking at the source with Firebug.