Scrolling to element in android app using java

Hi @Aleksei

Thank you Aleksi, really appreciate the effort for guiding me, able to print the webview now.

Is there a scroll down command in WebView? how to code it? is it the same with Protractor for Angular web like below? Thank you

driver.context(“WEBVIEW_com.cimb.ekyc”);
driver.executeScript(‘window.scrollTo(0,3000);’);

you may try whatever you remember from web. most will work. in many cases you do not need to scroll. try click.

Hi @Aleksei

I did my code and I synched my chrome driver but received error 404 as shown below, how to click on the text ? Am I using the right selector for selenium/appium webview -> By.linkText . Thanks Aleksei

            Thread.sleep(5000);
	**Set<String> contexts = driver.getContextHandles();**
		
	for(String contextName: contexts)
	{
		
		System.out.println(contextName);
	}
	
	driver.context("WEBVIEW_com.cimb.ekyc");
            driver.executeScript("window.scrollTo(0,900);");
            driver.findElement(By.linkText("R navigation icon Regular Savings Account Unlock higher interest rates as you save more")).click();
           Thread.sleep(5000);
	driver.quit();

Error in Appium:
Got an unexpected response with status 404: {“value”:{“error”:“no such element”,“message”:"no such element: Unable to locate element: {“method”:“link text”,“selector”:“R navigation icon Regular Savings Account Unlock higher interest rates as you save more”}\n (Session info:

Ui Inspector:

do not use Appium inspector. you are in webView now while i see inspector in Native.

print page source in a why i mentioned before with “Document doc…”

Hi @Aleksei,

I did the code you provided above, correct me if I am wrong, the code includes “Jsoup”? because having error on it.

“Jsoup cannot be resolved” – I am new to Java, is there any import code for this?

Hi @Aleksei,

I tried below, still having error. I am using Java. Thanks

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

I just use the appium ui inspector to illustrate, but i am using now the Set contexts = driver.getContextHandles()

you may try simple:

System.out.println(driver.getPageSource());

just output will be not nice.

Hi @Aleksei,

I got the output in XML and it is raw format. I paste in my Notepad++, which value you want me to search in here?.

Here is the value I am looking for → <android.view.View index=“11” text=“R navigation icon Regular Current Account Your payment and trading activities are made easy” class=“android.view.View” package=“com.cimb.ekyc” content-desc=“” checkable=“false” checked=“false” clickable=“true” enabled=“true” focusable=“true” focused=“false” scrollable=“false” long-clickable=“false” password=“false” selected=“false” bounds=“[70,2958][322,1208]” resource-id=“” instance=“18”/>

How to click or select this element? I was able to scroll and see this value in my mobile panel device but unable to click on it, clicking it will result to 404

Hi @Aleksei,

Good morning, I have now the formatted XML, how to select this and what selector to use to select the value that I want if the content-desc and resource-id are all empty? Thank you.

I coded like this: --is this syntax possible on webview?
driver.findElement(By.xpath("//android.view.View[@text=‘R navigation icon Regular Current Account Your payment and trading activities are made easy’ and @index=‘11’]")).click();

Error:
ProxyRequestError: Could not proxy command to remote server. Original error: 404 - {“value”:{“error”:“no such element”,“message”:"no such element: Unable to locate element

You are in Native context not WebView. Switch to webView first. Then take page source.

Hi @Aleksei,

Just a clarification, switch means to use the code below, right? Im still new here, isn’t the xml I paste is webview? Thank you

Set contexts = driver.getContextHandles();

	for(String contextName: contexts)
	{
		
		System.out.println(contextName);
		System.out.println(driver.getPageSource());
	}
	
	driver.context("WEBVIEW_com.cimb.ekyc");

Hi,

Ok, the routine you have shared me on the earlier comment. switching to web view.
But when I paste it and tried using it, having error on the line of code below

Document doc = Jsoup.parseBodyFragment(driver.findElement(By.cssSelector(“body”)).getAttribute(“outerHTML”));
System.out.println("\n" + doc.toString());

“Jsoup cannot be resolved” – is there any import code for this?

I have the pagesource, using the driver.getPageSource() and got the value as
<android.view.View index=“11” text=“R navigation icon Regular Current Account Your payment and trading activities are made easy” class=“android.view.View” package=“com.cimb.ekyc” content-desc="" checkable=“false” checked=“false” clickable=“true” enabled=“true” focusable=“true” focused=“false” scrollable=“false” long-clickable=“false” password=“false” selected=“false” bounds="[70,2958][322,1208]" resource-id="" instance=“18”/>

after this line you will be switched to webView. and after this you should execute:

System.out.println(driver.getPageSource());

with “System.out.println(contextName);” you have only NATIVE + WEBVIEW_com.cimb.ekyc. is it? cause sometimes app have several webViews.

1 Like

Hi @Aleksei,

Here is the value: (formatted to XML),i cannot paste it here, it is being converted to a link

any logs or large text put ONLY here -> https://gist.github.com/
create gist and send link here

here it is @Aleksei
How will i know the link or clickable elements here? which selector I can select. Thanks

webview%20march25

put it all on https://gist.github.com/ . looking at only partial source cant tell anything.

with WebView try:

driver.findElement(By.cssSelector("a[href*='CADEPA0001']")).click();

where “CADEPA0001” is unique text in href attribute in WHOLE page. you need to check this.

1 Like

Hi @Aleksei,

I tried my code to experiment only as given below but it did not work…
driver.findElement(By.className(“//product-title[@text="Regular Current Account"]”)).click();

I have tried your code, it works successfully…Thank you @Aleksei, I really appreciate the hand you have given me and the technical aspect of appium (native and webview). it is now working…Thanks once again…I didn’t know this hybrid app is giving me 3 days to scroll and click on other elements…ahahahaha(still learning)

Hi @Aleksei,

Is it possible to use css selector for text value? for example all my WebView are having the same values and classes. How can I use the css selector to SENDKEYS to a field?

My code: But I am having error as I cannot find the element
driver.findElement(By.cssSelector(“android.view.View:contains(‘Mobile Number’)”)).sendKeys(“0173398331”);