I cannot Select an Element with the AndroidFindBy - selenium

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.

Related

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')]"));

How to select dropdown while scripting in appium

I am using Selenium Webdriver with Java and Appium to automate a mobile application, I have 1 field where I need to select a value its not typically a drop down. Manually when we select, we need to click on the element and scroll and select a value. I tried using,
driver.scrollToExact("8").click();
but this is not working.
Can you please help me on this.
on my understandings of questions
1) if you are in native app then use xpath,
2) if you are in web view try using SELECT method.

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!

Selenium Web driver - No such element error while clicking an element

Script in UI
<div class=navdeactive>Technology</div>
While executing the below script
#driver.find_element(:link_text, "Technology").click
Getting an error>>
Selenium::WebDriver::Error::NoSuchElementError: The element could not
be found
But in view, source link is available.
Web Driver version: selenium-webdriver (2.25.0)
Help me on this
Based on your question you can use xpath and click the particular Html locator.
i have been given below script using python web driver. try this one.
driver.find_element_by_xpath("//a[text()='Technology']").click()
Answer:
In UI text is displayed as TECHNOLOGY But in the Page View Source text is displayed as Technology I have changed the code as #driver.find_element(:link_text, "TECHNOLOGY").click...... Now its worked fine...

Selenium (WebDriver) cannot see richfaces modal panel

I'm having some issues trying to test elements inside a RichFaces modal panel, as the one
in the demo page of RichFaces here
the issue is that once retrieved an element I cannot interact with it because WebDriver throws a ElementNotVisibleException.
I check it with firebug, and it appears greyed out, because some of the divs have height and width set to 0.
I tried to set all the divs manually with a height and size to see if it changes but there is no way to make it work, so I suppose there must be something else affecting the visibility of the modal panel, but cannot find what.
Has anyone tested webdriver or selenium against a richfaces panel?
Thanks in advance.
Edit:
For the code, is too much to put here, but basically I adapted the jbehave tutorial for the etsy website (the one using spring to inject dependencies), that can be found here.
The architecture is using a PropertyWebDriverProvider that is configured by maven properties to use InternetExplorer or Firefox and is using PageObject pattern (all the pages extend from WebDriverPage).
For specific code, the one from JimEvans gives me the same error.
The following code seems to work for me using the demo site you linked to in your question. It gets the text content of the modal panel, then clicks the "button" to close the panel.
public void testPanel() {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://livedemo.exadel.com/richfaces-demo/richfaces/modalPanel.jsf?c=modalPanel");
WebElement panelShow = driver.findElement(By.id("j_id352:link"));
panelShow.click();
WebElement panel = driver.findElement(By.id("j_id352:panelCDiv"));
WebElement panelTextElement = panel.findElement(By.className("rich-mpnl-body"));
System.out.println(panelTextElement.getText());
WebElement panelCloseButton = panel.findElement(By.id("j_id352:hidelink"));
panelCloseButton.click();
}
Only solution I found out was to do all the interaction with javascript through webdriver