---
name: Get Page Source
short_description: Get the current application hierarchy XML (app) or page source (web)

description:
  |
    In a web context, the source returns the source HTML of the current window. In a native context (iOS, Android, etc...) it will return the application hierarchy XML.

    This method is useful for inspecting your application hierarchy and using that to write [selectors](/docs/en/commands/element/find-element.md)

    (NOTE: iOS and Android don't have standard ways of defining their application source, so on calls to 'Get Page Source' Appium traverses the app hierarchy 
    and creates an XML document. Thus, getting the source can oftentime be an expensive and time-consuming operation) 

example_usage:
  java:
    |
      String pageSource = driver.getPageSource();
  python:
    |
      source = self.driver.page_source()
  javascript_wd:
    |
      let pageSource = await driver.source();
  javascript_wdio:
    |
      let source = driver.source();
  ruby:
    |
      @driver.page_source
  php:
    |
      // TODO PHP sample
  csharp:
    |
      // TODO C# sample

client_docs:
  java: "https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/RemoteWebDriver.html#getPageSource--"
  python: "http://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.page_source"
  javascript_wdio: "http://webdriver.io/api/protocol/source.html"
  javascript_wd: "https://github.com/admc/wd/blob/master/lib/commands.js#L1808"
  ruby: "http://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Driver:page_source"
  php: "https://github.com/appium/php-client/" # TODO PHP documentation link
  csharp: "https://github.com/appium/appium-dotnet-driver/" # TODO Dotnet documentation link

# Driver support by platform
driver_support:
  ios:
    xcuitest: true
    uiautomation: true
  android:
    uiautomator2: true
    uiautomator: true
  mac:
    mac: true
  windows:
    windows: true
client_support:
  java: true
  python: true
  ruby: true
  php: true
  csharp: true
  javascript_wd: true
  javascript_wdio: true
  

# Information about the HTTP endpoints
endpoint:
  url: /wd/hub/session/:session_id/source
  method: GET
  url_parameters:
    - name: session_id
      description: ID of the session to route the command to
  response:
    - type: string
      description: The sources of current context.

# Links to specifications. Should link to at least one specification
specifications: 
  w3c: https://www.w3.org/TR/webdriver/#dfn-get-page-source
  jsonwp: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidsource
