How to get result from getPageSource() method of WebDriver.

1,741 views
Skip to first unread message

Sumeet

unread,
Apr 1, 2014, 10:34:30 AM4/1/14
to appium-...@googlegroups.com
Hi,

I am not able to get result from getPageSource() method of RemoteWebDriver. 

Please check below mention code and result, and suggest me any resolution on it.
Code:-
                DesiredCapabilities capabilities = new DesiredCapabilities();
 
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability("device", "Android"); //Android
capabilities.setCapability("device Type", "Android");//Selendroid
capabilities.setCapability(CapabilityType.VERSION, "4.2.2");
capabilities.setCapability(CapabilityType.PLATFORM, "Windows");

                capabilities.setCapability("app", "C:\\Android Apps\\LinkedIn.apk");
capabilities.setCapability("app-package","com.linkedin.android");
capabilities.setCapability("app-activity",".authenticator.AuthenticatorActivity");

                driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

                Thread.sleep(1000);

                String pageSource = driver.getPageSource();
if(pageSource != null) {
System.out.println("pageSource is not null");
System.out.println("Length:- " + pageSource.length());
} else {
System.out.println("pageSource is null");
}
   System.out.println("The page source is : " + pageSource);

Result:- 
               [TestNG] Running:
                                        C:\Users\MySystem\AppData\Local\Temp\testng-eclipse--2101915057\testng-customsuite.xml

               pageSource is not null
               Length:- 0
               The page source is : 
                PASSED: testLinkedIn

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================

Thanks in advance for fruitful suggestion.. :-)


Thanks,
Sumeet.

Imon

unread,
Apr 1, 2014, 1:20:34 PM4/1/14
to appium-...@googlegroups.com
Your code looks fine. Is the app loaded before the getPageSource() is called? I have used a similar code in my test and it gives me the entire pageSource just fine.

Jonathan Lipps

unread,
Apr 1, 2014, 2:13:27 PM4/1/14
to Sumeet, appium-...@googlegroups.com
Did you look at the Appium logs to see what they are doing when you send the page source request in?

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Sumeet

unread,
Apr 2, 2014, 1:34:18 AM4/2/14
to appium-...@googlegroups.com
Hi Imon,
 
I checked. application already loaded in device properly, and I increased time gap interval also via Thread.sleep() method, but still no any content coming from getPageSource() method.
 
Thanks,
Sumeet.

Sumeet

unread,
Apr 2, 2014, 2:40:09 AM4/2/14
to appium-...@googlegroups.com, Sumeet
Hi Jonathan,
 
Please take a look on below appium logs, and tell me whats going wrong in it. You can directly focus on highlighted text.
 
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\sumeet.guha>appium
info: Welcome to Appium v0.16.0 (REV 292d265edd9c7aaf96f165009285c814b218363d)
info: Appium REST http interface listener started on 0.0.0.0:4723
   info  - socket.io started
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"platform":"Windows
","app":"C:\\Android Apps\\LinkedIn.apk","browserName":"Android","device Type":"
Android","app-package":"com.linkedin.android","device":"Android","app-activity":
".authenticator.AuthenticatorActivity","version":"4.2.2"}}
info: Using local app from desiredCaps: C:\Android Apps\LinkedIn.apk
info: Creating new appium session 2d5f78d3-6ecb-4f0e-ba50-3c175a8052b2
info: Starting android appium
debug: Using fast reset? true
info: Preparing device for session
info: Checking whether app is actually present
info: Checking whether adb is present
info: [ADB] Using adb from C:\Android-sdk\platform-tools\adb.exe
info: Trying to find a connected android device
info: [ADB] Getting connected devices...
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" devices
info: [ADB] 1 device(s) connected
info: Setting device id to 4d00311a7e7930eb
info: [ADB] Waiting for device to be ready and to respond to shell commands (tim
eout = 5)
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb wa
it-for-device
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "echo 'ready'"
info: Starting logcat capture
info: Getting device API level
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "getprop ro.build.version.sdk"
info: Device is at API Level 17
debug: java -jar "C:\Users\sumeet.guha\AppData\Roaming\npm\node_modules\appium\l
ib\devices\android\helpers\strings_from_apk.jar" "C:\Android Apps\LinkedIn.apk"
"C:\Windows\Temp\com.linkedin.android"
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb pu
sh "C:\\Windows\\Temp\\com.linkedin.android\\strings.json" /data/local/tmp
info: Checking whether aapt is present
info: [ADB] Using aapt from C:\Android-sdk\build-tools\19.0.1\aapt.exe
debug: processFromManifest: "C:\Android-sdk\build-tools\19.0.1\aapt.exe" dump xm
ltree C:\Android Apps\LinkedIn.apk AndroidManifest.xml
warn: ERROR: dump failed because resource Apps\LinkedIn.apk found
debug: Not uninstalling app since server not started with --full-reset
info: MD5 for app is e177ac075685adb6c2d7a151cc2b3567
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "ls /data/local/tmp/e177ac075685adb6c2d7a151cc2b3567.apk"
debug: Getting install status for com.linkedin.android
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "pm list packages -3 com.linkedin.android"
info: [ADB] App is installed
info: Running fastClear
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "am force-stop com.linkedin.android"
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "pm clear com.linkedin.android"
info: [ADB] Forwarding system:4724 to device:4724
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb fo
rward tcp:4724 tcp:4724
debug: Pushing appium bootstrap to device...
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb pu
sh "C:\\Users\\sumeet.guha\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\
android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
debug: Pushing unlock helper app to device...
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb in
stall "C:\Users\sumeet.guha\AppData\Roaming\npm\node_modules\appium\build\unlock
_apk\unlock_apk-debug.apk"
info: Attempting to kill all 'uiautomator' processes
info: Getting all processes with 'uiautomator'
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "ps 'uiautomator'"
info: No matching processes found
info: Running bootstrap
debug: spawning: C:\Android-sdk\platform-tools\adb.exe -s 4d00311a7e7930eb shell
 uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstra
p
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.boots
trap.Bootstrap
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [BOOTSTRAP] [info] Socket opened on port 4724
info: [BOOTSTRAP] [info] Appium Socket Server Ready
info: [BOOTSTRAP] [info] Loading json...
debug: Waking up device if it's not alive
info: Pushing command to appium work queue: ["wake",{}]
info: [BOOTSTRAP] [info] json loading complete.
info: [BOOTSTRAP] [info] Registered crash watchers.
info: [BOOTSTRAP] [info] Client connected
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"wake","
params":{}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: wake
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "dumpsys window"
info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
info: Writing dumpsys output to C:\Users\sumeet.guha\AppData\Roaming\npm\node_mo
dules\appium\.dumpsys.log
debug: Screen already unlocked, continuing.
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCH
ER -f 0x10200000 -n com.linkedin.android/.authenticator.AuthenticatorActivity"
info: Waiting for activity to  be focused
info: Getting focused package and activity
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "dumpsys window windows"
info: Device launched! Ready for commands (will time out in 60secs)
info: Appium session started with sessionId 2d5f78d3-6ecb-4f0e-ba50-3c175a8052b2
POST /wd/hub/session 303 8731ms - 9b
debug: Appium request initiated at /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175
a8052b2
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"platform":"Window
s","browserName":"Android","version":"4.2.2","webStorageEnabled":false,"takesScr
eenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"app":"C:\\Androi
d Apps\\LinkedIn.apk","device Type":"Android","app-package":"com.linkedin.androi
d","device":"Android","app-activity":".authenticator.AuthenticatorActivity"},"se
ssionId":"2d5f78d3-6ecb-4f0e-ba50-3c175a8052b2"}
GET /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175a8052b2 200 5ms - 495b
debug: Appium request initiated at /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175
a8052b2/timeouts/implicit_wait
debug: Request received with params: {"ms":30000}
info: Set Android implicit wait to 30000ms
info: Responding to client with success: {"status":0,"value":null,"sessionId":"2
d5f78d3-6ecb-4f0e-ba50-3c175a8052b2"}
POST /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175a8052b2/timeouts/implicit_wait
 200 6ms - 89b
debug: Appium request initiated at /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175
a8052b2/source
debug: Request received with params: {}
info: Pushing command to appium work queue: ["dumpWindowHierarchy"]
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"action","action":"dumpWin
dowHierarchy","params":{}}
info: [BOOTSTRAP] [info] Got command of type ACTION
info: [BOOTSTRAP] [debug] Got command action: dumpWindowHierarchy
info: [BOOTSTRAP] [info] Returning result: {"value":true,"status":0}
debug: transferPageSource command: "C:\Android-sdk\platform-tools\adb.exe" -s 4d
00311a7e7930eb pull /data/local/tmp/dump.xml "C:\Users\SUMEET~1.GUH\AppData\Loca
l\Temp\11432-9428-8rivet.xml"
warn: remote object '/data/local/tmp/dump.xml' does not exist
info: Responding to client with success: {"status":0,"value":"","sessionId":"2d5
f78d3-6ecb-4f0e-ba50-3c175a8052b2"}
GET /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175a8052b2/source 200 122ms - 87b
debug: Appium request initiated at /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175
a8052b2
debug: Request received with params: {}
info: Shutting down appium session...
info: [ADB] Pressing the HOME button
debug: executing: "C:\Android-sdk\platform-tools\adb.exe" -s 4d00311a7e7930eb sh
ell "input keyevent 3"
info: Stopping logcat capture
debug: Logcat terminated with code null, signal SIGTERM
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"shutdown"}
info: [BOOTSTRAP] [info] Got command of type SHUTDOWN
info: [BOOTSTRAP] [info] Returning result: {"value":"OK, shutting down","status"
:0}
info: [BOOTSTRAP] [info] Closed client connection
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.boots
trap.Bootstrap
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [UIAUTOMATOR STDOUT] Time: 7.841
info: [UIAUTOMATOR STDOUT] OK (1 test)
info: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: Sent shutdown command, waiting for UiAutomator to stop...
info: UiAutomator shut down normally
info: Cleaning up android objects
info: Cleaning up appium session
info: Responding to client with success: {"status":0,"value":null,"sessionId":"2
d5f78d3-6ecb-4f0e-ba50-3c175a8052b2"}
DELETE /wd/hub/session/2d5f78d3-6ecb-4f0e-ba50-3c175a8052b2 200 691ms - 89b
 
 
Thanks,
Sumeet.

Sumeet

unread,
Apr 3, 2014, 1:48:30 AM4/3/14
to appium-...@googlegroups.com, Sumeet
Hi Jonathan,

Any suggestion or idea on this issue.
I am eagerly waiting for your response.

Thanks,
Sumeet.

On Tuesday, 1 April 2014 23:43:27 UTC+5:30, Jonathan Lipps wrote:
Message has been deleted

Sumeet

unread,
Apr 3, 2014, 2:41:57 PM4/3/14
to appium-...@googlegroups.com, Sumeet
Hi,
Anyone can give me any fixed for this issue.
Atleast share idea or guess reason behind this issue.

Thanks,
Sumeet.

Imon

unread,
Apr 4, 2014, 2:56:35 PM4/4/14
to appium-...@googlegroups.com, Sumeet
Instead of Thread.sleep() try implementing a dynamic wait that will check for the object to be present. Try this code out.

WebElement myDynamicElement = (new WebDriverWait(driver, 20))

          .until(ExpectedConditions.presenceOfElementLocated(By.name("Name of the object that would confirm loading of the page")));

Reply all
Reply to author
Forward
0 new messages