• 作业一

    @pytest.mark.parametrize('username, password',
    [('********', '*******')
    ])
    def test_douban(self, username, password):
    self.driver = webdriver.Chrome()
    self.driver.implicitly_wait(6)
    self.driver.get("https://www.douban.com")
    login_iframe = self.driver.find_element_by_tag_name('iframe')
    self.driver.switch_to.frame(login_iframe)
    self.driver.find_element_by_class_name('account-tab-account').click()
    self.driver.find_element_by_id('username').send_keys(username)
    self.driver.find_element_by_name('password').send_keys(password)
    self.driver.find_element_by_link_text('登录豆瓣').click()
    elements = self.driver.find_elements_by_link_text("我的豆瓣")
    assert len(elements) > 0
    page = self.driver.page_source
    assert '说句话' in page
  • Author only
  • Author only
  • 如果想要把driver单独放到一个类初始化使用下面代码,后续调用要怎么写才能保证不会重复调用拉起设备,是否每个Page需要单独调用get_driver方法进行初始化,如果使用老师上课的办法,不想在每个class都使用Appium.getDriver(). 这种方式调用的话,是否能够将其参数化

    def __init__(self):
    caps = {"platformName": "android",
    "deviceName": "demo",
    "appPackage": "com.xueqiu.android",
    "appActivity": ".view.WelcomeActivityAlias",
    "unicodeKeyboard": True,
    "resetKeyboard": True,
    "autoGrantPermissions": True}
    self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

    def get_driver(self):
    return self.driver
  • 经典问题回帖保留

    使用Page_source去断言有时候出现报错,此问题是由于页面还未完全记载就去执行获取page_source的操作,故而在获取page_source操作的时候需要封装一个判断是否Loadin完成的方法,并且判断条件必须以最后出现的控件为准

    ..\testcase\test_xueqiu.py <appium.webdriver.webdriver.WebDriver (session="69b484d8-50dc-4d85-958b-f6389d3bd764")>
    F
    testcase\test_xueqiu.py:47 (TestXueQiu.test_add_us[\u767e\u5ea6])
    self = <XueQiu.testcase.test_xueqiu.TestXueQiu object at 0x0000000004643240>
    stockname = '百度'

    @pytest.mark.parametrize("stockname", [
    "百度", "阿里巴巴", "腾讯"
    ])
    # 搜索并添加股票
    def test_add_us(self, stockname):
    home_page = XueQiuHome()
    search = home_page.to_search()
    search.search(stockname)
    search.search_add()
    search.to_optional()
    > assert stockname in BaseView.getDriver().page_source

    ..\testcase\test_xueqiu.py:58:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    F:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py:679: in page_source
    return self.execute(Command.GET_PAGE_SOURCE)['value']
    F:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
    self.error_handler.check_response(response)
    F:\Python37\lib\site-packages\appium\webdriver\errorhandler.py:29: in check_response
    raise wde
    F:\Python37\lib\site-packages\appium\webdriver\errorhandler.py:24: in check_response
    super(MobileErrorHandler, self).check_response(response)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <appium.webdriver.errorhandler.MobileErrorHandler object at 0x0000000004578CC0>
    response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"An unknown server-side error occurred while pro...Timeout (timers.js:300:5)\\n at listOnTimeout (timers.js:263:5)\\n at Timer.processTimers (timers.js:223:10)"}}'}

    def check_response(self, response):
    """
    Checks that a JSON response from the WebDriver does not have an error.

    :Args:
    - response - The JSON response from the WebDriver server as a dictionary
    object.

    :Raises: If the response contains an error message.
    """

    status = response.get('status', None)
    if status is None or status == ErrorCode.SUCCESS:
    return
    value = None
    message = response.get("message", "")
    screen = response.get("screen", "")
    stacktrace = None
    if isinstance(status, int):
    value_json = response.get('value', None)
    if value_json and isinstance(value_json, basestring):
    import json
    try:
    value = json.loads(value_json)
    if len(value.keys()) == 1:
    value = value['value']
    status = value.get('error', None)
    if status is None:
    status = value["status"]
    message = value["value"]
    if not isinstance(message, basestring):
    value = message
    message = message.get('message')
    else:
    message = value.get('message', None)
    except ValueError:
    pass

    exception_class = ErrorInResponseException
    if status in ErrorCode.NO_SUCH_ELEMENT:
    exception_class = NoSuchElementException
    elif status in ErrorCode.NO_SUCH_FRAME:
    exception_class = NoSuchFrameException
    elif status in ErrorCode.NO_SUCH_WINDOW:
    exception_class = NoSuchWindowException
    elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
    exception_class = StaleElementReferenceException
    elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
    exception_class = ElementNotVisibleException
    elif status in ErrorCode.INVALID_ELEMENT_STATE:
    exception_class = InvalidElementStateException
    elif status in ErrorCode.INVALID_SELECTOR \
    or status in ErrorCode.INVALID_XPATH_SELECTOR \
    or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
    exception_class = InvalidSelectorException
    elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
    exception_class = ElementNotSelectableException
    elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
    exception_class = ElementNotInteractableException
    elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
    exception_class = InvalidCookieDomainException
    elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
    exception_class = UnableToSetCookieException
    elif status in ErrorCode.TIMEOUT:
    exception_class = TimeoutException
    elif status in ErrorCode.SCRIPT_TIMEOUT:
    exception_class = TimeoutException
    elif status in ErrorCode.UNKNOWN_ERROR:
    exception_class = WebDriverException
    elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
    exception_class = UnexpectedAlertPresentException
    elif status in ErrorCode.NO_ALERT_OPEN:
    exception_class = NoAlertPresentException
    elif status in ErrorCode.IME_NOT_AVAILABLE:
    exception_class = ImeNotAvailableException
    elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
    exception_class = ImeActivationFailedException
    elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
    exception_class = MoveTargetOutOfBoundsException
    elif status in ErrorCode.JAVASCRIPT_ERROR:
    exception_class = JavascriptException
    elif status in ErrorCode.SESSION_NOT_CREATED:
    exception_class = SessionNotCreatedException
    elif status in ErrorCode.INVALID_ARGUMENT:
    exception_class = InvalidArgumentException
    elif status in ErrorCode.NO_SUCH_COOKIE:
    exception_class = NoSuchCookieException
    elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
    exception_class = ScreenshotException
    elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
    exception_class = ElementClickInterceptedException
    elif status in ErrorCode.INSECURE_CERTIFICATE:
    exception_class = InsecureCertificateException
    elif status in ErrorCode.INVALID_COORDINATES:
    exception_class = InvalidCoordinatesException
    elif status in ErrorCode.INVALID_SESSION_ID:
    exception_class = InvalidSessionIdException
    elif status in ErrorCode.UNKNOWN_METHOD:
    exception_class = UnknownMethodException
    else:
    exception_class = WebDriverException
    if value == '' or value is None:
    value = response['value']
    if isinstance(value, basestring):
    if exception_class == ErrorInResponseException:
    raise exception_class(response, value)
    raise exception_class(value)
    if message == "" and 'message' in value:
    message = value['message']

    screen = None
    if 'screen' in value:
    screen = value['screen']

    stacktrace = None
    if 'stackTrace' in value and value['stackTrace']:
    stacktrace = []
    try:
    for frame in value['stackTrace']:
    line = self._value_or_default(frame, 'lineNumber', '')
    file = self._value_or_default(frame, 'fileName', '<anonymous>')
    if line:
    file = "%s:%s" % (file, line)
    meth = self._value_or_default(frame, 'methodName', '<anonymous>')
    if 'className' in frame:
    meth = "%s.%s" % (frame['className'], meth)
    msg = " at %s (%s)"
    msg = msg % (meth, file)
    stacktrace.append(msg)
    except TypeError:
    pass
    if exception_class == ErrorInResponseException:
    raise exception_class(response, message)
    elif exception_class == UnexpectedAlertPresentException:
    alert_text = None
    if 'data' in value:
    alert_text = value['data'].get('text')
    elif 'alert' in value:
    alert_text = value['alert'].get('text')
    raise exception_class(message, screen, stacktrace, alert_text)
    > raise exception_class(message, screen, stacktrace)
    E selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Server socket stopped responding. The recent response was '{"status":0,"value":"<?xml version=\"1.0\" encoding=\"UTF-8\"?><hierarchy rotation=\"0\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" resource-id=\"\" instance=\"0\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" resource-id=\"\" instance=\"0\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" resource-id=\"\" instance=\"1\"><android.view.View index=\"0\" text=\"\" class=\"android.view.View\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" resource-id=\"com.xueqiu.android:id\/decor_content_parent\" instance=\"0\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" resource-id=\"android:id\/content\" instance=\"2\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" resource-id=\"\" instance=\"1\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1650]\" resource-id=\"\" instance=\"3\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1650]\" resource-id=\"com.xueqiu.android:id\/mainContent\" instance=\"4\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1650]\" resource-id=\"\" instance=\"5\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1650]\" resource-id=\"\" instance=\"6\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1650]\" resource-id=\"com.xueqiu.android:id\/stock_index_quote_view\" instance=\"7\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1650]\" resource-id=\"\" instance=\"2\"><android.view.View index=\"0\" text=\"\" class=\"android.view.View\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1558]\" resource-id=\"com.xueqiu.android:id\/mask_view\" instance=\"1\"\/><android.widget.FrameLayout index=\"1\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1559][1080,1650]\" resource-id=\"\" instance=\"8\"><android.support.v4.view.ViewPager index=\"0\" text=\"\" class=\"android.support.v4.view.ViewPager\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"true\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1559][1080,1650]\" resource-id=\"com.xueqiu.android:id\/multi_market_index_pager\" instance=\"0\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1559][1080,1650]\" resource-id=\"\" instance=\"9\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1559][1080,1650]\" resource-id=\"\" instance=\"10\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1559][1080,1650]\" resource-id=\"com.xueqiu.android:id\/single_line_wrapper\" instance=\"3\"><android.view.View index=\"0\" text=\"\" class=\"android.view.View\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1559][1080,1560]\" resource-id=\"\" instance=\"2\"\/><android.widget.LinearLayout index=\"1\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1560][1080,1650]\" resource-id=\"\" instance=\"4\"><android.widget.ViewFlipper index=\"0\" text=\"\" class=\"android.widget.ViewFlipper\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1560][948,1650]\" resource-id=\"com.xueqiu.android:id\/single_line_flipper_view\" instance=\"0\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,1560][948,1650]\" resource-id=\"\" instance=\"5\"><android.widget.TextView index=\"0\" text=\"上证指数\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[36,1576][294,1633]\" resource-id=\"com.xueqiu.android:id\/single_line_quote_name\" instance=\"0\"\/><android.widget.LinearLayout index=\"1\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[294,1579][948,1630]\" resource-id=\"\" instance=\"6\"><android.widget.TextView index=\"0\" text=\"2969.86\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[294,1579][509,1630]\" resource-id=\"com.xueqiu.android:id\/single_line_quote_price\" instance=\"1\"\/><android.widget.TextView index=\"1\" text=\"-136.56\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[509,1579][721,1630]\" resource-id=\"com.xueqiu.android:id\/single_line_quote_change\" instance=\"2\"\/><android.widget.TextView index=\"2\" text=\"-4.40%\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[721,1579][948,1630]\" resource-id=\"com.xueqiu.android:id\/single_line_quote_pct\" instance=\"3\"\/><\/android.widget.LinearLayout><\/android.widget.LinearLayout><\/android.widget.ViewFlipper><android.widget.ImageView index=\"1\" text=\"\" class=\"android.widget.ImageView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[1008,1587][1044,1623]\" resource-id=\"\" instance=\"0\"\/><\/android.widget.LinearLayout><\/android.widget.LinearLayout><\/android.widget.FrameLayout><\/android.widget.FrameLayout><\/android.support.v4.view.ViewPager><\/android.widget.FrameLayout><\/android.widget.LinearLayout><\/android.widget.FrameLayout><android.widget.FrameLayout index=\"1\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,0][1080,1560]\" resource-id=\"com.xueqiu.android:id\/portfolio_root_view\" instance=\"11\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,75][1080,1560]\" resource-id=\"\" instance=\"12\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,75][1080,1560]\" resource-id=\"\" instance=\"7\"><android.widget.RelativeLayout index=\"0\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,75][1080,219]\" resource-id=\"\" instance=\"0\"><android.widget.RelativeLayout index=\"0\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,75][156,219]\" resource-id=\"\" instance=\"1\"><android.widget.ImageButton NAF=\"true\" index=\"0\" text=\"\" class=\"android.widget.ImageButton\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,75][156,219]\" resource-id=\"com.xueqiu.android:id\/action_message\" instance=\"0\"\/><android.widget.ImageView index=\"1\" text=\"\" class=\"android.widget.ImageView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[82,105][152,150]\" resource-id=\"com.xueqiu.android:id\/unread_count\" instance=\"1\"\/><\/android.widget.RelativeLayout><android.widget.LinearLayout index=\"2\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[684,111][1080,183]\" resource-id=\"\" instance=\"8\"><android.widget.ImageButton NAF=\"true\" index=\"0\" text=\"\" class=\"android.widget.ImageButton\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[684,111][816,183]\" resource-id=\"com.xueqiu.android:id\/action_search\" instance=\"1\"\/><android.widget.ImageButton NAF=\"true\" index=\"1\" text=\"\" class=\"android.widget.ImageButton\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[816,111][948,183]\" resource-id=\"com.xueqiu.android:id\/action_create_cube\" instance=\"2\"\/><android.widget.ImageButton NAF=\"true\" index=\"2\" text=\"\" class=\"android.widget.ImageButton\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[948,111][1080,183]\" resource-id=\"com.xueqiu.android:id\/action_more\" instance=\"3\"\/><\/android.widget.LinearLayout><\/android.widget.RelativeLayout><android.widget.RelativeLayout index=\"1\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,219][1080,1560]\" resource-id=\"\" instance=\"2\"><android.widget.RelativeLayout index=\"0\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,219][1080,340]\" resource-id=\"com.xueqiu.android:id\/rl_tab_indicator\" instance=\"3\"><android.widget.FrameLayout index=\"0\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,220][960,340]\" resource-id=\"com.xueqiu.android:id\/indicator_with_shadow\" instance=\"13\"><android.widget.HorizontalScrollView index=\"0\" text=\"\" class=\"android.widget.HorizontalScrollView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"false\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,220][960,340]\" resource-id=\"com.xueqiu.android:id\/indicator\" instance=\"0\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,220][960,340]\" resource-id=\"\" instance=\"9\"><android.widget.RelativeLayout index=\"0\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[12,220][199,339]\" resource-id=\"\" instance=\"4\"><android.widget.TextView index=\"0\" text=\"全部\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[45,247][165,312]\" resource-id=\"\" instance=\"4\"\/><android.view.View index=\"1\" text=\"\" class=\"android.view.View\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[75,321][135,330]\" resource-id=\"\" instance=\"3\"\/><\/android.widget.RelativeLayout><android.widget.RelativeLayout index=\"1\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[199,220][386,339]\" resource-id=\"\" instance=\"5\"><android.widget.TextView index=\"0\" text=\"沪深\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[232,247][352,312]\" resource-id=\"\" instance=\"5\"\/><\/android.widget.RelativeLayout><android.widget.RelativeLayout index=\"2\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[386,220][573,339]\" resource-id=\"\" instance=\"6\"><android.widget.TextView index=\"0\" text=\"港股\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[419,247][539,312]\" resource-id=\"\" instance=\"6\"\/><\/android.widget.RelativeLayout><android.widget.RelativeLayout index=\"3\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[573,220][760,339]\" resource-id=\"\" instance=\"7\"><android.widget.TextView index=\"0\" text=\"美股\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[606,247][726,312]\" resource-id=\"\" instance=\"7\"\/><\/android.widget.RelativeLayout><android.widget.RelativeLayout index=\"4\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[760,220][948,339]\" resource-id=\"\" instance=\"8\"><android.widget.TextView index=\"0\" text=\"模拟\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[794,247][914,312]\" resource-id=\"\" instance=\"8\"\/><\/android.widget.RelativeLayout><\/android.widget.LinearLayout><\/android.widget.HorizontalScrollView><\/android.widget.FrameLayout><android.widget.ImageView NAF=\"true\" index=\"1\" text=\"\" class=\"android.widget.ImageView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[960,219][1080,339]\" resource-id=\"com.xueqiu.android:id\/edit_group\" instance=\"2\"\/><android.view.View index=\"2\" text=\"\" class=\"android.view.View\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,339][1080,340]\" resource-id=\"\" instance=\"4\"\/><\/android.widget.RelativeLayout><android.support.v4.view.ViewPager index=\"1\" text=\"\" class=\"android.support.v4.view.ViewPager\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"true\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,340][1080,1560]\" resource-id=\"com.xueqiu.android:id\/pager\" instance=\"1\"><android.view.View index=\"0\" text=\"\" class=\"android.view.View\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,340][1080,1560]\" resource-id=\"com.xueqiu.android:id\/smart_refresh_layout\" instance=\"5\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,340][1080,1560]\" resource-id=\"com.xueqiu.android:id\/container_view\" instance=\"10\"><android.widget.RelativeLayout index=\"0\" text=\"\" class=\"android.widget.RelativeLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,364][1080,496]\" resource-id=\"\" instance=\"9\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,364][1080,496]\" resource-id=\"\" instance=\"11\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,364][450,496]\" resource-id=\"com.xueqiu.android:id\/item1_ll\" instance=\"12\"><android.widget.TextView index=\"0\" text=\"股票\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[36,403][114,456]\" resource-id=\"com.xueqiu.android:id\/stock_name\" instance=\"9\"\/><\/android.widget.LinearLayout><android.widget.TextView index=\"1\" text=\"最新价\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[450,364][744,496]\" resource-id=\"com.xueqiu.android:id\/btn_current\" instance=\"10\"\/><android.widget.LinearLayout index=\"2\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[744,364][1044,496]\" resource-id=\"\" instance=\"13\"><android.widget.TextView index=\"0\" text=\"涨跌幅\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[759,364][969,496]\" resource-id=\"com.xueqiu.android:id\/btn_change\" instance=\"11\"\/><android.widget.ImageView NAF=\"true\" index=\"1\" text=\"\" class=\"android.widget.ImageView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[984,364][1044,496]\" resource-id=\"com.xueqiu.android:id\/portfolio_turn_to_fullscreen\" instance=\"3\"\/><\/android.widget.LinearLayout><\/android.widget.LinearLayout><android.view.View index=\"1\" text=\"\" class=\"android.view.View\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,495][1080,496]\" resource-id=\"\" instance=\"6\"\/><\/android.widget.RelativeLayout><android.widget.LinearLayout index=\"1\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,496][1080,1560]\" resource-id=\"\" instance=\"14\"><android.widget.FrameLayout index=\"1\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,496][1080,1560]\" resource-id=\"\" instance=\"14\"><android.widget.ListView index=\"0\" text=\"\" class=\"android.widget.ListView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"true\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,496][1080,1560]\" resource-id=\"com.xueqiu.android:id\/listview\" instance=\"0\"><android.widget.FrameLayout index=\"2\" text=\"\" class=\"android.widget.FrameLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[0,496][1080,646]\" resource-id=\"\" instance=\"15\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"true\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"true\" password=\"false\" selected=\"false\" bounds=\"[0,496][1080,646]\" resource-id=\"com.xueqiu.android:id\/portfolio_whole_item\" instance=\"15\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[36,508][601,634]\" resource-id=\"\" instance=\"16\"><android.widget.LinearLayout index=\"0\" text=\"\" class=\"android.widget.LinearLayout\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[36,508][132,586]\" resource-id=\"\" instance=\"17\"><android.widget.TextView index=\"0\" text=\"百度\" class=\"android.widget.TextView\" package=\"com.xueqiu.android\" content-desc=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" scrollable=\"false\" long-clickable=\"false\" password=\"false\" selected=\"false\" bounds=\"[36,508][132,586]\" resource-id=\"com.xueqiu.android:id\/portfolio_stockName\" instance=\"12\"\/><\/android.widget.LinearLayout><android.widge'

    F:\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: WebDriverException

    Process finished with exit code -1
  • 作业四

    Test Case:

    @pytest.mark.parametrize("stockname", [
    "百度", "阿里巴巴", "腾讯"
    ])
    # 搜索并添加股票
    def test_add_us(self, stockname):
    home_page = XueQiuHome()
    search = home_page.to_search()
    search.search(stockname)
    search.search_add()
    search.to_optional()
    assert stockname in BaseView.getDriver().page_source

    HomePage:

    class BaseView(object):
    driver = None
    """type: webdriver"""

    @classmethod
    def getDriver(cls):
    return cls.driver

    @classmethod
    def initDriver(cls):
    caps = {"platformName": "android",
    "deviceName": "demo",
    "appPackage": "com.xueqiu.android",
    "appActivity": ".view.WelcomeActivityAlias",
    "unicodeKeyboard": True,
    "resetKeyboard": True,
    "autoGrantPermissions": True}
    cls.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    cls.driver.implicitly_wait(6)

    SearchPage:

    class Search(object):
    _search_input = (By.ID, "search_input_text") # 搜索输入框
    _add_1st = (By.XPATH, "//*[contains(@resource-id,'follow_btn') and @instance=9]") # 每个搜索的第一只股票
    _stock_cancal = (By.ID, "action_close") # 搜索取消按钮
    _optional = (By.XPATH, "//*[@text='自选' and contains(@resource-id,'tab_name')]") # 自选按钮

    def search(self, keyword):
    MyAppium().my_find(*self._search_input).send_keys(keyword)
    return self

    def search_add(self):
    stock_added = MyAppium().myelement_exist(*self._add_1st) # 检测股票是否已添加
    if stock_added:
    MyAppium().my_find(*self._add_1st).click()
    return self

    def to_optional(self):
    MyAppium().my_find(*self._stock_cancal).click()
    MyAppium().my_find(*self._optional).click()
    MyMethod().loaded(False)
    return self

    Utils MyAppium

    class MyAppium(object):

    def myelement_exist(self, *args):
    myelement = BaseView.getDriver().find_elements(*args) # 根据查找方法和定位符获取元素信息
    if len(myelement) >= 1: # 如果元素或列表存在则不为空
    return True
    else:
    return False

    def my_find(self, by, locate, timeout=30):
    end_time = time.time() + timeout
    while True:
    if self.myelement_exist(by, locate):
    return BaseView.getDriver().find_element(by, locate)
    elif time.time() > end_time:
    print("查找超时,当前页面信息如下:", BaseView.getDriver().page_source)
    break
    else:
    mypage = BaseView.getDriver().page_source
    # 建立白名单,通过XPATH将随时可能出现的按钮处理掉
    whitelist = ["//*[@text='允许']", "//*[@text='创建您的专属选股策略']",
    "//*[@text='下次再说']", "//*[contains(@resource-id,'iv_close')]",
    "//*[contains(@resource-id,'image_cancel')]", "//*[contains(@resource-id,'closeBtn')]"]
    rule = "['](.*?)[']"
    for key in whitelist:
    keyword = re.search(rule, key).group(1) # 通过正则把keyword提取出来
    if keyword in mypage: # 检测keyword是否在当前页面存在
    BaseView.getDriver().find_element(By.XPATH, key).click()
    break

    Utils OwnMethod

    class MyMethod:
    _optional = (By.XPATH, "//*[@text='自选' and contains(@resource-id,'tab_name')]") # 自选按钮
    _stock_code = (By.ID, "portfolio_stockCode") # 股票英文名

    # 封装页面加载检测方法
    def loaded(self, no_stock=True):
    locations = []
    while True:
    if no_stock:
    loc = MyAppium().my_find(*self._optional) # 检测主页是否加载完毕
    else:
    loc = MyAppium().my_find(*self._stock_code) # 检测自选股是否加载完毕
    locations.append(loc.location)
    if len(locations) >= 2 and locations[-1] == locations[-2]:
    break
  • 作业一

    def myelement_exist(self, *args):
    myelement = BaseView.getDriver().find_elements(*args) # 根据查找方法和定位符获取元素信息
    if len(myelement) >= 1: # 如果元素或列表存在则不为空
    return True
    else:
    return False

    def my_swipe(self, list_by, list_value, director="up", *args):
    x = BaseView.getDriver().get_window_size()['width'] # 获取当前设备的宽度
    y = BaseView.getDriver().get_window_size()['height'] # 获取当前设备的高度
    if director == "up": # X轴不变,Y轴从下往上
    mystart_x = x * 0.5
    mystart_y = y * 0.8
    myend_x = x * 0.5
    myend_y = y * 0.2
    elif director == "down": # X轴不变,Y轴从上往下
    mystart_x = x * 0.5
    mystart_y = y * 0.2
    myend_x = x * 0.5
    myend_y = y * 0.8
    elif director == "left": # Y轴不变,X轴从右往左
    mystart_x = x * 0.8
    mystart_y = y * 0.5
    myend_x = x * 0.2
    myend_y = y * 0.5
    elif director == "right": # Y轴不变,X轴从左往右
    mystart_x = x * 0.2
    mystart_y = y * 0.5
    myend_x = x * 0.8
    myend_y = y * 0.5
    else:
    print("请输入正确的滑动方向")

    while True:
    BaseView.getDriver().swipe(mystart_x, mystart_y, myend_x, myend_y, duration=400)
    if self.myelement_exist(*args): # 检测所找元素是否存在
    return BaseView.getDriver().find_element(*args)
    else:
    all_elements = []
    new_elements = []
    elements = BaseView.getDriver().find_elements(list_by, list_value) # 获取当前列表信息
    if len(all_elements) == 0 and len(elements) > 0:
    for x in elements:
    all_elements.append(x.text)
    elif len(elements) > 0: # 当前列表非空
    for x in elements:
    new_elements.append(x.text)
    if new_elements[:-1] == all_elements[:-1]: # 当前最后元素与之前最后一个元素对比
    print("滑动已到底")
    break
    else:
    all_elements += new_elements
    else:
    print("当前列表无元素存在")
    break
  • 作业三

    def test_webview(self):
    self.loaded()
    self.driver.find_element_by_xpath("//*[@text='交易']").click()
    self.driver.find_element_by_xpath("//*[@text='基金']").click()
    WebDriverWait(self.driver, 20).until(EC.presence_of_element_located(By.XPATH, "//*[@text='已有蛋卷基金账户登录']"))
    contexts = self.driver.contexts
    self.driver.switch_to.context(contexts[1])
    self.driver.find_element_by_xpath("//*[@text='已有蛋卷基金账户登录']").click()

    WebDriverWait(self.driver, 20).until(EC.presence_of_element_located(By.XPATH, "//*[@text='使用密码登录']"))
    contexts = self.driver.contexts
    self.driver.switch_to.context(contexts[1])
    self.driver.find_element_by_xpath("//*[@text='使用密码登录']").click()
    self.driver.find_element_by_xpath("//*[@text='请输入手机号']").send_keys("13312345678")
    self.driver.find_element_by_xpath("//*[@text='请输入密码']").send_keys("dsadsaf")
    self.driver.find_element_by_xpath("//*[@text='安全登录']").click()
  • Uiautomatorview没有显示webview的控件信息

  • appium desktop查看控件信息