1. 我测试的是手机浏览器 H5 页面,写测试的时候发现,每次进入到新的页面,在操作前都需要切到新的 WEBVIEW,否则报错找不到元素。
    如下示例:

    #WEBVIEW
    switch_to_webview(self.driver).wait_for_element("id","icenterFooter").click()
    switch_to_webview(self.driver).wait_for_element("link text","登录").click()
    switch_to_webview(self.driver).wait_for_element("xpath","//li[@tab='prReg']").click()
    self.driver.wait_for_element("class name",'name').send_keys("111111111")
    self.driver.wait_for_element("name",'password').send_keys("xxxx")
    self.driver.wait_for_element('class name','loginBtn').click()
    
    time.sleep(3)
    switch_to_webview(self.driver).wait_for_element('id','ilistFooter').click()        #点击保险
    switch_to_webview(self.driver).wait_for_element('xpath',"//li[@data-tab='jiankang']").click()
    
  1. 另外 driver.close(),我再测试完成后关闭手机浏览器标签页时报错:
Error
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 331, in run
    testMethod()
  File "/Users/jinlong/Desktop/myspace/macaca-demo/macaca_chrome.py", line 57, in test_get_url
    switch_to_webview(self.driver).close()
  File "/Users/jinlong/Desktop/env/lib/python2.7/site-packages/macaca/util.py", line 145, in fluent_interface
    ret = func(instance, *args, **kwargs)
  File "/Users/jinlong/Desktop/env/lib/python2.7/site-packages/macaca/webdriver.py", line 259, in close
    self._execute(Command.CLOSE)
  File "/Users/jinlong/Desktop/env/lib/python2.7/site-packages/macaca/webdriver.py", line 68, in _execute
    ret.raise_for_status()
  File "/Users/jinlong/Desktop/env/lib/python2.7/site-packages/macaca/webdriverresult.py", line 54, in raise_for_status
    raise WebDriverException(error, message, screen, stacktrace)
WebDriverException: 
Error: WebDriverError.UNKNOWN_ERROR
Message: unknown error: failed to close window in 20 seconds
  (Session info: chrome=53.0.2785.146)
  (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Mac OS X 10.10.5 x86_64)

请问这是用法问题吗请大神指导


↙↙↙阅读原文可查看相关链接,并与作者交流