I want to scroll down to till the particular web element is present and then I will assert particular element is present or not.
I have tried with below coding for scrolling down the to reach the end of the page.
Below code scrolls down, if it reaches the end of the page. It throws error.
I need to do one scroll, after that i will check particular element is present or not, if that element is present means, I need to break from the loop.
I have defined the loop in static manner as i<=10 times. How can I give that loop condition in dynamically?
How can I do my scenario?
code:-
// scroll down action
for (int i = 0; i <= 10; i++) {
System.out.println(“1…”);
WebElement element = driver
.findElementByName(“save_button”);
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObjects = new HashMap<String, String>();
scrollObjects.put(“direction”, “down”);
scrollObjects.put(“element”,
((RemoteWebElement) element).getId());
js.executeScript(“mobile: scroll”, scrollObjects);
if (AppiumHelper.isElementPresent(driver, By.name(“Comment”)))
break;
}
sleep(9000);
Error Message:-
An error occurred while executing user supplied JavaScript. (WARNING: The server did not provide any stacktrace information)(…)
@Sargis_Azaryan, I have tried with above code, I need one clarification , if an element is not located in that page, If I scroll down only that particular element is visible means, how can I able to scroll till that particular element using above method.It throws below error message.
Failed tests: An element could not be located on the page using the given search parameters.
You can’t scroll to invisible element in android. Yet scrollToElement for android that i provided should work , unless you had upgraded your Appium to 1.5 version
@Sargis_Azaryan, I am having 1.4.16.1 (Ohiuchus) version. Please tell me how to upgrade to 1.5 version. Can you please share the staeps to do so. It will be really helpful.
You can use below mentioned method to swipe upward and call the method with a condition till that elemt gets displayed using driver.isdisplayed(). For ex: