el = driver.find_element_by_id("editText")
使用 find_element_by_id() 函数报错,程序中确实有此 id 控件,求大神指导
appium 报错:
info: [BOOTSTRAP] [debug] Finding container using ID with the contextId:
info: [BOOTSTRAP] [info] Returning result: {"value":"Could not find an element using supplied strategy. ID editText doesn't exist as text or content desc.","status":7}
info: Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"Could not find an element using supplied strategy. ID editText doesn't exist as text or content desc."},"sessionId":"aa94ae49-4817-495a-8c94-8aa42a7f4586"}
python-test:
from selenium import webdriver
import os
import unittest
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(file), p)
)
desired_caps = {}
#desired_caps['device'] = 'android'
#desired_caps['browserName'] = ''
#desired_caps['version'] = '4.4.2'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = '192.168.1.104:5554'
desired_caps['app'] = PATH(
'./test.apk'
)
desired_caps['app-package'] = 'com.example.test'
desired_caps['app-activity'] = '.MainActivity'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
el = driver.find_element_by_name("5")
el.click()
el = driver.find_element_by_name("2")
el.click()
el = driver.find_element_by_name("+")
el.click()
el = driver.find_element_by_name("1")
el.click()
el = driver.find_element_by_id("editText")
result = el.getText()
unittest.assertEqual(result, '521')
driver.quit()
android-xml:
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.MainActivity"
tools:ignore="MergeRootFrame" >
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="4"
android:cursorVisible="false"
android:editable="false"
android:gravity="right|center_vertical"
android:lines="1"
android:textSize="32sp" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:textSize="32sp" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="32sp" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="32sp" />
android:id="@+id/clear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="C"
android:layout_weight="1"
android:textSize="32sp" />
android:id="@+id/add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:textSize="32sp" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:textSize="32sp" >
android:id="@+id/num7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7"
android:textSize="32sp" />
android:id="@+id/num8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8"
android:textSize="32sp" />
android:id="@+id/num9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9"
android:textSize="32sp" />
android:id="@+id/subtract"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-"
android:textSize="32sp" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:textSize="32sp" >
android:id="@+id/num4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4"
android:textSize="32sp" />
android:id="@+id/num5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5"
android:textSize="32sp" />
android:id="@+id/num6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6"
android:textSize="32sp" />
android:id="@+id/multiply"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*"
android:textSize="32sp" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:textSize="32sp" >
android:id="@+id/num1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1"
android:textSize="32sp" />
android:id="@+id/num2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2"
android:textSize="32sp" />
android:id="@+id/num3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3"
android:textSize="32sp" />
android:id="@+id/divide"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="/"
android:textSize="32sp" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:textSize="32sp" >
android:id="@+id/num0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0"
android:textSize="32sp" />
android:id="@+id/point"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="."
android:textSize="32sp" />
android:id="@+id/negative"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-"
android:textSize="32sp" />
android:id="@+id/equal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="="
android:textSize="32sp" />