I can not execute Python Code generated in Appium Studio

hey guys,

I had a problem about Python Code generated in Appium Studio

I use appium studio version 20.5

Python code generated by appium studio cannot be run in pycharm (Python uses version 3. X)

Is there a python version problem?

by the way,
Is there any mistake here using find_element(locator) ? why adding xpath= before the element path
for example:
find_element_by_xpath(“xpath=//[@class=‘android.widget.ImageView’ and ./parent::[@id=‘menu_item_article’]]”).

import unittest
import time
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions

class _2(unittest.TestCase):
reportDirectory = ‘reports’
reportFormat = ‘xml’
dc = {}
testName = ‘2’
driver = None

def setUp(self):
    self.dc['reportDirectory'] = self.reportDirectory
    self.dc['reportFormat'] = self.reportFormat
    self.dc['testName'] = self.testName
    self.dc['udid'] = ''
    self.dc['platformName'] = 'android'
    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.dc)

def test_2(self):
    self.driver.find_element_by_xpath(
        "xpath=//*[@class='android.widget.ImageView' and ./parent::*[@id='menu_item_article']]").click()
    self.driver.find_element_by_xpath("xpath=//*[@class='android.widget.ImageButton']").click()
    self.driver.find_element_by_xpath(
        "xpath=//*[@class='android.widget.RelativeLayout' and ./*[@id='ll_tap' and ./*[@text='消息']]]").click()
    time.sleep(2.0)
    self.driver.find_element_by_xpath(
        "xpath=(//*[@class='android.widget.LinearLayout' and ./parent::*[@id='tab_bar']]/*/*/*[@id='iv_tab_icon'])[3]").click()
    time.sleep(2.0)
    self.driver.find_element_by_xpath(
        "xpath=//*[@id='widget_form_edit_text_edt_content' and ./parent::*[./parent::*[@id='edt_title']]]").send_keys(
        '123')
    self.driver.execute_script("seetest:client.deviceAction(\"Enter\")")
    self.driver.execute_script("seetest:client.sendText(\"456\")")
    WebDriverWait(self.driver, 10).until(
        expected_conditions.presence_of_element_located((By.XPATH, '//*[@class='android.widget.ImageButton']')))
    self.driver.find_element_by_xpath("xpath=//*[@class='android.widget.ImageButton']").click()
    self.driver.find_element_by_xpath("xpath=//*[@id='action_done']").click()

def tearDown(self):
    self.driver.quit()

if __name__ == '__main__':
    unittest.main()

find_element_by_xpath function appears to be valid function . What error you get ?

I want to put the recorded script on my pycharm and appium server
I copy the script to pycharm and run it, I found that the script report could not find the element. Then I deleted “XPath =” here, and the run could find the element
before:

self.driver.find_ element_ By_ xpath(

“xpath=//[@class=’ android.widget.ImageView ’ and ./parent::[@id=‘menu_ item_ article’]]”).click()

after:
self.driver.find_ element_ By_ xpath(

“//[@class=’ android.widget.ImageView ’ and ./parent::[@id=‘menu_ item_ article’]]”).click()