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

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

Related

Getting "Nosuch element Exception" in Selenium Though XPATH is correct. Not sure is this due to Shadow DOM. Please confirm

I am trying to automate Salesforce application Using Selenium and getting NoSuchelementException though XPATH is correct and valid for particular object. When i have searched the issue, it might be reason for Shadow DOM.
For EX:
So XAPTH i have written like,
driver.findElement(By.xpath("//input[#name='Name']")).sendKeys("Jams");
or
driver.findElement(By.xpath("//input[#id='input-299']")).sendKeys("Jams");
This XPATH is highlighting in Console as well. But while automating it throws nosuchelement error.
So while checking for ShadowDOM option, am getting option like this for Name Object.
#shadow-root(user-agent)
Shadowroot DIV
-- nothing mentioned in div. it just open and closed tags.
How to automate this?
You can check if there are any iframes in your Dom. Simply do //iframe in your page developer mode(F12)> elements tab > search (Ctrf+F) area. If there are any, you will get the number of iframes.
Now if your textbox is in any of iframe use below code to go inside particular iframe first
driver.switch_to.frame("<name or Id of frame>")
then come out to frame use below:
driver.switch_to.parent_frame()
Also, if the issue is not related to frames check below for shadow-root related issue:
you can check below for shadow-root element ( Question is for Java, but you can co-relate):
How to interact with the elements within #shadow-root (open) while Clearing Browsing Data of Chrome Browser using cssSelector
The website contents are mostly created now using javascript. You may have to wait for certain elements to load before doing anything to it.
https://seleniumbyexamples.github.io/wait

Finding xpath of shadow dom elements with robot framework

I'm writing automated UI tests using Robot Framework with python. I'm testing a Polymer application that uses the shadow dom Robot's standard libraries don't seem to be able to locate elements in the shadow dom using xpath.
I've been sorting through selenium's repo/overflow/internets and polymer's repo/overflow/internets and haven't found the intersection of a solution for using robot with python (the selenium workaround isn't that graceful either). I was hoping someone had run into this issue with this specific framework that might be willing to share a solution (or note that there's not one).
Test Case
Wait Until Page Contains Element xpath=(//html/body/some-root-shadow-dom-element/input)
This of course results in an error because the shadow dom is not put into the main document of the DOM tree.
Open the browser console and type this into the console:
dom:document.querySelector("apply-widget").shadowRoot.querySelectorAll("div)
Make sure to hit enter after so it will be ran.

"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.

Identifying ExtJS elements with selenium webdriver

I am having handling a drop down button in EXTJS application which i am trying to automation with selenium web driver.
clicking on the image i will get a list of elements in the form of 's
to click select from
Please help me how i can device a xpath to click this image, which i should not use "id" (as its extjs it might vary every now and then).
if there are any selector i can use for extjs please suggest. Thanks for your help.
<DIV id=ext-gen2337 class=x-form-field-wrap style="WIDTH: 0px"><INPUT id=ext-gen2023 class=" x-form-text x-form-field" style="WIDTH: 297px" readOnly size=24 value="Clients with pending exceptions" name=ext-gen2023 autocomplete="off"><IMG id=ext-gen2338 class="x-form-trigger x-form-arrow-trigger" src="https:REDACTED/com.ssc.epw.gui.EPWHome/clear.cache.gif">
Try below XPath to match required img element:
//input[#value="Clients with pending exceptions"]/following-sibling::img
So if you want to start testing ExtJS app and you don't want to use the best solution for this such as Sencha Test or Bryntum Siesta.
The best way to approach this is to write you own layer between the ExtJS components and the html dom of the site.
You can see more info in my answer here https://stackoverflow.com/a/41718879/1768843
But what you need to do is to use the Ext.Component.Query, with Selenium you can execute the javascript code on the site. So you execute the ext query and you pass there the Ext selector - for example button[text=something] or panel[name=mainPanel] simply any ExtJS component selector. This will return you the ExtJS object and with it you can simply call .getDom() or .getId() which will return you the actual dom or id used in the HTML. Next you can simply use the webdriver functions for clicking (or something) on the HTML elements in the site.
^^ You need to do this because the ExtJS framework can generate the HTML every-time little bit differently. For example you add new container or you upgrade your ExtJS version and the HTML is changed and your test can stop working. But if you call the Ext components as log as the Ext source code is still the same your tests will be always working.
But doing this is quite a hassle and lot of work. It's much better to use prepared solutions such as Sencha Test where everything is already prepare for testing ExtJS apps.
I would do something like this:
driver.findElement(By.xpath("//div[contains(#class, 'x-form-field-wrap')]//img"));
or
driver.findElement(By.xpath("//img[contains(#src, 'https://REDACTED/com.ssc.epw.gui.EPWHome/clear.cache.gif')]"));

Unable to click button in mobile web in appium

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!