请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

An unknown server-side error occurred while processing the command. 这什么错

from appium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import sys
sys.path.append(r'C:\Users\Administrator\PycharmProjects\appium_new')
from util.readConfig import read_ini
from util.get_by_local import locate_element
from appium import webdriver
from testcase.swipe import swipe



class test_login:
   def get_driver(self):
       capabilities = {
           "platformName": "Android",
           "deviceName": "127.0.0.1:62001",
           "app": "C:\\Users\\Administrator\\PycharmProjects\\appium_new\\apk\\mukewang.apk"
           , "noReset": "true",
           "automationName": "UiAutomator2"
       }
       self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', capabilities)
       print(self.driver.current_activity)
       time.sleep(10)  # 不能省,启动需要时间
       return self.driver


   def login(self):
       locate = locate_element(self.get_driver())
       no_update = self.driver.find_element_by_id('cn.com.open.mooc:id/positiveBtn')
       no_update.click()
       mine = self.driver.find_elements_by_class_name('android.support.v7.app.ActionBar$Tab')
       mine[3].click()
       time.sleep(2)
       self.driver.find_element_by_xpath('//*[contains(@text,"点击登录")]').click()

     
       phone = self.driver.find_element_by_id('cn.com.open.mooc:id/account_edit')
       phone.clear()
       phone.send_keys('13166427863')
       
       password = self.driver.find_element_by_id('cn.com.open.mooc:id/password_edit')
       password.clear()
       password.send_keys('x')
     
       login_button = self.driver.find_element_by_id('cn.com.open.mooc:id/login')
       login_button.click()

   def test_webview(self):
       # mine = driver.find_elements_by_class_name('android.support.v7.app.ActionBar$Tab')
       # mine[1].click()
       time.sleep(4)
       webview = self.driver.contexts
       print(webview)

   def get_toast(self):
       phone = self.driver.find_element_by_id('cn.com.open.mooc:id/account_edit')
       phone.clear()
       phone.send_keys('13166427863')
       self.driver.find_element_by_xpath('//*[contains(@text,"点击登录")]').click()
       toast_element = ("xpath", "//*[contains(@tsxt,'请输入密码')]")
       WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(toast_element))

test_login=test_login()

# swipe=swipe()
# swipe.swipe_on('left')
# swipe.swipe_on('left')
# time.sleep(2)
# swipe.swipe_on('left')
# driver.find_element_by_id('cn.com.open.mooc:id/viewpager').click()

test_login.login()

C:\python32\python.exe C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py

com.imooc.component.imoocmain.splash.MCSplashActivity

Traceback (most recent call last):

  File "C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py", line 75, in <module>

    test_login.login()

  File "C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py", line 46, in login

    password.send_keys('x')

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys

    'value': keys_to_typing(value)})

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute

    return self._parent.execute(command, params)

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute

    self.error_handler.check_response(response)

  File "C:\python32\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response

    raise wde

  File "C:\python32\lib\site-packages\appium\webdriver\errorhandler.py", line 24, in check_response

    super(MobileErrorHandler, self).check_response(response)

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response

    raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: java.lang.NullPointerException

at android.support.test.uiautomator.UiObject2.setText(UiObject2.java:601)

at io.appium.uiautomator2.model.UiObject2Element.setText(UiObject2Element.java:129)

at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:83)

at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:56)

at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:202)

at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:193)

at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)

at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)

at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)

at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)

at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)

at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)

at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:514)

at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:468)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)

at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)

at java.lang.Thread.run(Thread.java:841)




Process finished with exit code 1


正在回答 回答被采纳积分+3

2回答

提问者 wxbq00 2018-07-24 11:25:15

Traceback (most recent call last):

  File "C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py", line 75, in <module>

    test_login.login()

  File "C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py", line 31, in login

    locate = locate_element(self.get_driver())

  File "C:/Users/Administrator/PycharmProjects/appium_new/testcase/test.py", line 24, in get_driver

    self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', capabilities)

  File "C:\python32\lib\site-packages\appium\webdriver\webdriver.py", line 36, in __init__

    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__

    self.start_session(capabilities, browser_profile)

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 245, in start_session

    response = self.execute(Command.NEW_SESSION, parameters)

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute

    self.error_handler.check_response(response)

  File "C:\python32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response

    raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device.


现在又死活连不上设备,用的模拟器


0 回复 有任何疑惑可以回复我~
Mushishi 2018-07-20 22:46:05

你好,代码看着没问题,但是报错说send出错,这个你把appiuum得运行日志截图发一下。我看一下哪里有错误。

0 回复 有任何疑惑可以回复我~
  • 提问者 wxbq00 #1
    连不上设备怎么办
    回复 有任何疑惑可以回复我~ 2018-07-24 11:25:34
  • Mushishi 回复 提问者 wxbq00 #2
    adb connect去链接
    回复 有任何疑惑可以回复我~ 2018-07-24 20:58:52
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信