@amitjaincoer191 Here is my scenario
Scenario 1:-
- There are 20 article in the page
- Only 5 articles are displayed. Other articles are displayed when you scroll
- How can i scroll with x and y co-ordinates and find an expected article. I want to reach 20th article and click it.
- This is list of articles page, Here you see 5 articles are displayed.
Scenario 2:-
- Article content is displayed
- There are more paragraphs are displayed in an article. In centre of the page , mobile ad(Image) will be displayed.
- Mobile Ad(Image) will be displayed only when we scroll to position of centre of an article. I want to verify that image is present or not.
- This is a article page, When you scroll, Mobile Ad(image) will be displayed
How can i do it above scenarios?
@amitjaincoer191
I have tried the following Scenario1 for scroll a page. Scroll happens at once. Then its get stopped
Scenario 1:-
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.5;
int scrollStart = screenHeightStart.intValue();
System.out.println("s="+scrollStart);
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int scrollEnd = screenHeightEnd.intValue();
driver.swipe(0,scrollStart,0,scrollEnd,2000);
sleep(10000);
Scenario2:-
I have tried following for scroll. Scroll is happening till end of page and it keep on scrolling for some time and throws error.
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.5;
int scrollStart = screenHeightStart.intValue();
System.out.println("s="+scrollStart);
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int scrollEnd = screenHeightEnd.intValue();
for (int i = 0; i < dimensions.getHeight(); i++) {
driver.swipe(0,scrollStart,0,scrollEnd,2000);
}
I need to stop scrolling when it reach of end of page.
What I need to change here to make it work perfectly.
You can only conclude that u reach to end of page if u r test case says to click this element
so put terminating condition like
for (int i = 0; i < dimensions.getHeight(); i++) {
driver.swipe(0,scrollStart,0,scrollEnd,2000);
if (driver.findElement(By.name("YourText")).size()>0)
exit;
}
driver.findElement(By.name("YourText")).click();
so with this for each scroll it will check that element is visible if yes it will come out of loop and click it else it keeps on scrolling.
@amitjaincoer191 OK THANKS.
@amitjaincoer191 Consider I have reached end of page. I am trying to do scrolling, control won't beyond page as it is reached end of page.
I am trying to do driver.swipe method in end of page. How can i say I can able to do swipe or not ?
@amitjaincoer191, can you explain why you're using startx+20 and moving to endx+20? If i'm not wrong, the +20 indicates the pixels. So, when you're moving from point A to point B, the coordinates should be (x,y) to (x+20,y+20), is that right?
It depends how u want to move
(0,0) (0,10) - move 10 units in y direction vertical up swipe (0,10) - move 10 units in y direction vertical down swipe (10,0) - move 10 units in x direction horizontal right swipe (10,0) - move 10 units in x direction [horizontal left swipe]
+20 or -20 from computed coordinates using getLocation.getX() / getLocation.getY() simply means a kind of error removing way some time computed coordinates are on extreme boundary of screen so swipe goes wrong
@Karunakaran_M and @amitjaincoer191
Scenario 1:- worked for me
Thanks a lot
Hi,
scenario 1 works well for me if the element I am looking for exist.
But if it doesn't exist how can I stop the for loop when I reach the end of the page, if I don't know the last element of the page?
More precisely,
I am trying to check if a given element exist in a page. To do that, I use the scenario 1.
It's perfect if the element is found but if it isn't found, the scenario 1 continue to run until the end of "for" loop is reached, even if the end of the page is reached.
I can't know the last element of the page because it's a list that is specific for each App user and that can be change (add / remove element).
Thanks.
Here is the workaround for scroll in Android - https://pioneer2k9.blogspot.in/2016/08/workaround-or-solution-for-deprecated.html590
Thank you Karunakaran_M.
I already used the workaround with the swipe method and loop a predetermined number of time to find a specific element.
But I wonder, instead to have a predetermined number of time:
for i=0; i <10; i++,
we can have a way something like:
for i=0; i < "end of page"; i++ OR while(! "end of age")
where "end of page" is not fix <=> not necessary the same element at the end of the page.
So far, I swipe screen by screen and retrieve the last element text of the current screen, and compare with the previous last element text (of the previous screen).
If it's the same => I reach the end of the page and stop the loop.
But I am not sure it's the best way to do that
Have a nice day
When I login into an iOS App, in the next page, I have to click on a “Next” button in the bottom of that page .
For that I have to scroll down.
I have been trying to use the below code, but it isn’t working for me:
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.5;
int scrollStart = screenHeightStart.intValue();
System.out.println("s="+scrollStart);
Double screenHeightEnd = dimensions.getHeight() * 0.1;
int scrollEnd = screenHeightEnd.intValue();
for (int i = 0; i < dimensions.getHeight(); i++)
{
driver.swipe(0,scrollStart,0,scrollEnd,2000);
if (driver.findElement(By.id("Next")).isDisplayed())
break;
}
Please help me with how to tackle this problem. It is scrolling upwards instead of down