Description
Is there an existing issue for this?
- I have searched the existing issues
Appium Version
2.18.0
Appium Host Type
Command Line
Are you using Appium components not maintained by the Appium team?
No
Is this issue reproducible using the latest components?
- I confirm the issue is still reproducible with the latest component versions
Current Behavior
When I try to use driver.PageSource
I get different results on different platforms (Windows 11 and Linux).
On Windows, for example, driver.PageSource
parse structure like this (simplified):
<hierarchy rotation="0" width="1080" height="2163">
<widget.FrameLayout>
<widget.LinearLayout>
<widget.FrameLayout>
<widget.LinearLayout resource-id="/action_bar">
<widget.FrameLayout resource-id="/content">
<widget.FrameLayout resource-id="/container">
<widget.LinearLayout>
<view.ViewGroup resource-id="/profile">
<widget.ImageButton content-desc="Back" />
<widget.TextView text="Some My Text" />
</view.ViewGroup>
<!-- etc -->
But at the same time, on Linux I get this result:
<hierarchy rotation="0" width="1080" height="2163">
<widget.FrameLayout>
<widget.LinearLayout>
<widget.FrameLayout>
<widget.LinearLayout resource-id="/action_bar">
<widget.FrameLayout resource-id="/content">
<widget.FrameLayout resource-id="/container">
<widget.FrameLayout> <!-- This is not what expected -->
<widget.LinearLayout>
<view.ViewGroup resource-id="/profile">
<widget.ImageButton content-desc="Back" />
<widget.TextView text="Some My Text" />
</view.ViewGroup>
<!-- etc -->
Expected Behavior
That I will receive the same XML structure across different platforms:
<hierarchy rotation="0" width="1080" height="2163">
<widget.FrameLayout>
<widget.LinearLayout>
<widget.FrameLayout>
<widget.LinearLayout resource-id="/action_bar">
<widget.FrameLayout resource-id="/content">
<widget.FrameLayout resource-id="/container">
<widget.LinearLayout>
<view.ViewGroup resource-id="/profile">
<widget.ImageButton content-desc="Back" />
<widget.TextView text="Some My Text" />
</view.ViewGroup>
<!-- etc -->
Appium Log
No response
Environment Details
- .NET 8 with Appium.WebDriver (Version 5.1.0)
- Java 24.0.1 2025-04-15
- Node.js 22.16.0
- NPM 10.9.2
- Appium 2.18.0
- UiAutomator2 3.10.0
- adb 1.0.41
Also my initial setup was based on Appium 2.11.1 and UiAutomator2 3.7.0. Tried to update everything - but not helps for me.
Minimal Reproducible Example
Personally, I'm trying to get PageSource()
from LinkedIn App:
- Open someone profile.
- Open contact info page.
- Invoke
driver.PageSource()
and saveXML
result.
Unfortunately I can't create simple version of my code, but (sorry) here template from ChatGPT:
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using System.Diagnostics;
class Program
{
static void Main()
{
const int port = 10000;
const string udid = "<DEVICE_ID>";
var process = StartAppium(port);
Thread.Sleep(15000); // wait when appium server starts
var options = new AppiumOptions();
options.PlatformName = "Android";
options.PlatformVersion = "14";
options.AutomationName = "UiAutomator2";
options.AddAdditionalAppiumOption("udid", udid);
options.AddAdditionalAppiumOption("appium:systemPort", port + 200);
options.AddAdditionalAppiumOption("appium:noReset", true);
options.AddAdditionalAppiumOption("appium:newCommandTimeout", 0);
using var driver = new AndroidDriver(new Uri($"http://127.0.0.1:{port}/"), options);
Thread.Sleep(5000);
var xml = driver.PageSource;
xml = driver.PageSource; // If not invoke PageSource two times, result would be emtpy or not full.
File.WriteAllText("result.xml", xml);
driver.Quit();
process.Kill(true);
}
static Process StartAppium(int port)
{
string shell = OperatingSystem.IsWindows() ? "cmd.exe" : "/bin/bash";
string jsonCaps = $"{{\\\"appium:systemPort\\\": {port + 200}}}";
string args = OperatingSystem.IsWindows()
? $"/c appium -p {port} --default-capabilities \"{jsonCaps}\" --relaxed-security --allow-insecure chromedriver_autodownload"
: $"-c \"appium -p {port} --default-capabilities '{jsonCaps}' --relaxed-security --allow-insecure chromedriver_autodownload\"";
var psi = new ProcessStartInfo
{
FileName = shell,
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
var proc = new Process { StartInfo = psi };
proc.Start();
return proc;
}
}
Further Information
Also, I tried to use Appium Inspector.
And I can't see any difference in XML tree between windows and Linux, but PageSource return different trees.
Probably I waste not enough time exploring trees in Appium Inspector on Windows and Linux, so probably trees can be different...