Swiping to a element not present in dom in appium ios - appium

I have an app where a particular parent that has n elements lets say 10 elements (tiles) and only 5 are present in the dom and visible in the current screen. The next 5 would appear in dom/screen on swiping up. How do I swipe to a particular element say 7th element?
I'm not able to get find the element by id/name as the element is not in dom so I'm not able to use swipe until visibility of an element. also, the number of such elements varies based on how the backend system is configured so I cannot make a fixed number of swipes. Also since I do not know the last element in the parent I'm at risk of running into an infinite loop if the particular element is not present in the app (due to a bug).
Please help on how to solve this.

You can use following methods to scroll down until expected element. To avoid the infinite loop you can keep count of while loop.
public void scrollDown()
{
TouchAction action = new TouchAction((AppiumDriver)driver);
action.press(new PointOption().point(300, 701)).waitAction(newWaitOptions().waitOptions(Duration.ofSeconds(2))).moveTo(new PointOption().point(300, 441)).release();
action.perform();
}
public void scrollTillElement(By element)
{
int countofLoop = 0;
List<WebElement> elements = driver.findElements(element);
while (elements.size()==0)
{
countofLoop++;
scrollDown();
elements = driver.findElements(element);
if(countofLoop==20)
{
break;
}
}
}

Related

It doesn't always scroll to the same place, Appium Android

I am using the following method while scrolling android. but It doesn't always scroll to the same place, even though it's on the same page. what would be the reason.
public void ScrollToCampaignNotice(){
try {
getDriver().findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).flingToEnd(35)"));
} catch (InvalidSelectorException e) {
// ignore
}
}
At the same time, I tried the following method differently, it has the same problem.
You could scroll to exact element instead of flinging 35 times.
Here is an example how to scroll to specific text that is visible:
new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("<include your text>").instance(0))
You can also scroll to an element that has specific id like this:
new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId("<insert element ID here>").instance(0))

Vaadin grid - change component column in one row only

I have a grid with several columns. For three columns i used the column renderer. Each of the columns contains one button.
If i click one of those buttons, i want to replace the three buttons in that specific row with two other buttons. All the other rows should not be affected. Is this possible in a Vaadin grid?
Components in different columns don't know each other, as they are all defined in a separate scope (in the componentRenderer of their own column. You cannot define the Button outside of the componentRenderer as you found out in another question today). So the "obvious" solution won't work, where you add a clickListener on the Button to directly change the other buttons.
If you had one column with 3 Buttons inside then this would be much easier.
There is a way, but I see this more as a hack than as a solution. Because you need some extra implementation in the item class for this to work.
In the ComponentRenderer, you can add an if-statement where you look at some value of the item. In one case, you'll render button 1, in the other case you'll render the other button. And in the click listeners of the button you change that value in the item and refresh the dataprovider, so the componentRenderer is invoked again. It will now see the value on the item has changed, therefore displaying some other Button.
Here is some code to show what I mean:
// grid item class
public class Foo {
private boolean buttonPressed = false;
public Foo(){
}
public isButtonPressed(){
return buttonPressed;
}
public setButtonPressed(boolean buttonPressed){
this.buttonPressed = buttonPressed;
}
}
// adding of button columns
// do this 3 times for a test of your scenario.
grid.addComponentColumn(item -> {
if(!item.isButtonPressed()){
return new Button("Before Button was Pressed", click -> {
item.setButtonPressed(true);
grid.getDataProvider().refresh(item);
});
} else {
return new Button("Button was Pressed", click -> {
item.setButtonPressed(false);
grid.getDataProvider().refresh(item);
})
}
})

Pagination Of ListView On Scrolling In Xamarin.Android

Can Any one help Me on How to Implement on Handling Pagination on Scrolling of listview in xamarin.android .any link or any sample wil be helpful
Well, Android pagination is quite easy in comparison to iOS and can be done as follows:
public class EndlessScrollListener : Java.Lang.Object, Android.Widget.AbsListView.IOnScrollListener
{
private int visibleThreshold = 5;
private int currentPage = 0;
private int previousTotal = 0;
private bool loading = true;
public EndlessScrollListener()
{
}
public EndlessScrollListener(int visibleThreshold)
{
this.visibleThreshold = visibleThreshold;
}
public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
if (loading)
{
if (totalItemCount > previousTotal)
{
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold))
{
// I load the next page of gigs using a background task,
// but you can call any function here.
//new LoadGigsTask().execute(currentPage + 1);
loading = true;
}
}
public void OnScrollStateChanged(AbsListView view, [GeneratedEnum] ScrollState scrollState)
{
// throw new NotImplementedException();
}
}
Then set it to the listview as follows:
List.SetOnScrollListener(new EndlessScrollListener());
Working of code:
visibleThreshold – The minimum amount of items to have below your current scroll position, before loading more.
currentPage – The current page of data you have loaded.
previousTotal – The total number of items in the dataset after the last load.
loading – True if we are still waiting for the last set of data to load.
Next, we have a couple of constructors that allow us to set the visibleThreshold inline if we want.
The first overridden method we have is called every time the list is scrolled. This happens many times a second during a scroll, so be wary of the code you place here. We are given a few useful parameters to help us work out if we need to load some more data, but first, we check if we are waiting for the previous load to finish.
If it’s still loading, we check to see if the dataset count has changed, if so we conclude it has finished loading and update the current page number and total item count.
If it isn’t currently loading, we check to see if we have breached the visibleThreshold and need to reload more data. If we do need to reload some more data, we execute a background task and set the loading flag to true. Thus solving the problem forever!
The last method in the class we do not need, however, if you’re interested, it is primarily used for tracking changes in the scroll action itself via the scrollState parameter.
Finally, the code to call the class creates a new instance of EndlessScrollListener and bind’s it to a ListView of mine. Of course, put your own ListView in place of List.

Trackwheel Click Event Issue

I am dealing with KeywordFilterField which is populated with the list of the countries. Now the problem i am facing is that when i click the particular country it should move to the next screen as I have written the pushScreen code in the trackwheelClick event after checking that _keywordFilterField is focusable or not, but this is not the case. The Menu opens when trackwheelClick event is fired, at the center of the screen, rather than moving onto the next screen.Can anybody have the idea why Menu dialog opens on the trackwheelclick event instead of going to the next screen.
See what i have done on trackwheel click event:
protected boolean trackwheelClick(int status, int time) {
if (_keywordFilterField.isFocus()) {
int index = _keywordFilterField.getSelectedIndex();
ReadableList readableList = _keywordFilterField.getResultList();
Object selectedCountry = readableList.getAt(index);
String countryName=selectedCountry.toString();
urlutf8Encoder=new URLUTF8Encoder();
String newCountry=urlutf8Encoder.encode(countryName);
pushToSearchResult(newCountry,countryName);//To Next SCreen
return true;
}
return false;
}
But it looks like:
The trackwheelClick event returns a boolean that indicates whether the event is consumed. Once an event is consumed, it stops propagating to other UI elements. If you return true, the menu will stop appearing.

could not be able to work with list control in flex 4.5

I want to be selected that new Item in list when I give new value to dataProvider but it selects the item that was firstly selected, and how to make that selected permanently on App start up.
You if want to select the list item after added to dataProvider. Probably you follow this
list.selectedIndex = list.dataProvider.length -1;
Sometimes if you added at desired position like
list.dataProvider.setItemAt(obj,2);
list.selectedIndex = 2
If you want to selected item permanently on App start up.(Make sure that your array collections bind-able to list)
public function onCreationComplete(event:FlexEvent):void
{
callLater(function():void
{
list.selectedIndex = list.dataProvider.length -1;
list.ensureIndexIsVisible(list.selectedIndex); // Viewport
});
}

Resources