测试设备:Genymotion 5.1
Appium:V1.6.5
Python:3.5.3
用官方的https://github.com/appium/sample-code/tree/master/sample-code/examples/python/android_webview.py 学习 webview 的使用,在使用过程中报错 selenium.common.exceptions.InvalidElementStateException: Message: invalid element state: Element is not currently interactable and may not be manipulated.
def test_webview(self):
if (PLATFORM_VERSION == '4.4'):
button = self.driver.find_element_by_accessibility_id('buttonStartWebviewCD')
else:
button = self.driver.find_element_by_name('buttonStartWebviewCD')
button.click()
self.driver.switch_to.context('WEBVIEW_0')
input_field = self.driver.find_element_by_id('name_input')
sleep(1)
input_field.clear()
input_field.send_keys('Appium User')
input_field.submit()
# test that everything is a-ok
source = self.driver.page_source
self.assertNotEqual(-1, source.find('This is my way of saying hello'))
self.assertNotEqual(-1, source.find('"Appium User"'))
参考https://github.com/ariya/phantomjs/issues/11637,新增代码 self.driver.get('http://localhost:4450/'),修改之后代码:
def test_webview(self):
button = self.driver.find_element_by_accessibility_id('buttonStartWebviewCD')
button.click()
self.driver.switch_to.context('WEBVIEW')
input_field = self.driver.find_element_by_id('name_input')
#此处重新Load page
self.driver.get('http://localhost:4450/')
sleep(1)
input_field.clear()
input_field.send_keys('Appium User')
input_field.submit()
# test that everything is a-ok
source = self.driver.page_source
self.assertNotEqual(-1, source.find('This is my way of saying hello'))
self.assertNotEqual(-1, source.find('"Appium User"'))
Element is not currently interactable and may not be manipulated 报错的情况下,将当前界面的 webview 内容重新加载 driver.get(url)