title: Robot Framework - passing Appium driver to python script
body: <p>I'm working on integrating Robot Framework with Appium, using Python. However I can't figure out how to pass the Appium driver created in the Robot Framework to a custom python script.</p>
  
  <p>My Environment:</p>
  
  <ul>
  <li>Mac OS - Mavericks</li>
  <li>Appium 1.2 (installed via home brew)</li>
  <li>Latest Robot Framework (installed via pip)</li>
  <li>Latest Appium Library for Robot Framework (installed via pip)</li>
  </ul>
  
  <p>I have a working Appium script in Python, but I want to start using Robot Framework for handling the actual tests.</p>
  
  <p>partial code for working python script:</p>
  
  <pre><code>wd = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
  wd.find_element_by_name("Start").click()
  wd.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]").click()
  wd.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.typeString(\"Test Text\");")
  wd.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.buttons()['Return'].tap();")
  </code></pre>
  
  <p>As you can see, because of how the application is working, I ned to use execute_script as part of the script.</p>
  
  <p>The Appium Library for Robot Framework does not expose execute_script, so I need to write my own in a python library.</p>
  
  <p>Here's my start of the robot testing script, which does work up until the point where I need to execute_script:</p>
  
  <pre><code>TestStart
      Open Application   ${REMOTE_URL}    ${PLATFORM_NAME}    ${PLATFORM_VERSION}    ${DEVICE_NAME}    ${APP}
      Click Element    name=Start
      Click Element    xpath=//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]
  </code></pre>
  
  <p>My question is how do I get the driver instance created in the Open Application and pass it to a Python script?</p>
  
  <p>I have a python script that has the following:</p>
  
  <pre><code>def KeyboardType(driver):
      driver.execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.typeString(\"hi there\");")
  </code></pre>
  
  <p>However, I can't seem to be able to pass the driver from the Robot Framework script to this python script.</p>
  
  <p>I tried setting the Open Application to a variable via:</p>
  
  <pre><code>${Driver}  Open Application   ${REMOTE_URL}    ${PLATFORM_NAME}    ${PLATFORM_VERSION}    ${DEVICE_NAME}    ${APP}
  KeyboardType  ${Driver}
  </code></pre>
  
  <p>but I received the error:</p>
  
  <p>AttributeError: 'str' object has no attribute 'execute_script'</p>
  
  <p>I also tried passing the result of Get Current Context into the python script, but then I get:</p>
  
  <p>AttributeError: 'unicode' object has no attribute 'execute_script'</p>
  
  <p>How can I pass the driver created by the Robot Framework into the python script?</p>