多个chromedriver实例android

时间:2017-02-28 13:27:33

标签: python selenium selenium-webdriver selenium-chromedriver

我的代码看起来像这样

$ python --version
Python 3.5.2
$ pip --version
pip 9.0.1 from /home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages (python 3.5)
$ pip install .[test]
Processing /home/travis/build/Brian-Williams/repo_python
Collecting flake8 (from refactor-me==0.1.0)
  Downloading flake8-3.3.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 6.1MB/s 
Requirement already satisfied: pytest>=2.9.0 in /home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages (from refactor-me==0.1.0)
Collecting pycodestyle<2.4.0,>=2.0.0 (from flake8->refactor-me==0.1.0)
  Downloading pycodestyle-2.3.1-py2.py3-none-any.whl (45kB)
    100% |███████████████���████████████████| 51kB 10.6MB/s 
Collecting mccabe<0.7.0,>=0.6.0 (from flake8->refactor-me==0.1.0)
  Downloading mccabe-0.6.1-py2.py3-none-any.whl
Collecting pyflakes<1.6.0,>=1.5.0 (from flake8->refactor-me==0.1.0)
  Downloading pyflakes-1.5.0-py2.py3-none-any.whl (225kB)
    100% |████████████████████████████████| 225kB 7.1MB/s 
Requirement already satisfied: py>=1.4.29 in /home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages (from pytest>=2.9.0->refactor-me==0.1.0)
Installing collected packages: pycodestyle, mccabe, pyflakes, flake8, refactor-me
  Running setup.py install for refactor-me ... - done
Successfully installed flake8-3.3.0 mccabe-0.6.1 pycodestyle-2.3.1 pyflakes-1.5.0 refactor-me-0.1.0

现在这个代码的问题是当我启动第二个实例然后第一个实例关闭而我无法对其进行任何操作。 e.g

def _launch_android():
    log.info("launching chrome on android device")
    capabilities = {
        'chromeOptions': {
            'androidPackage': 'com.android.chrome',
        }
    }
    log.info("Verifying that android device is connected via USB")
    subprocess.Popen('adb devices')
    p = subprocess.Popen("adb devices", stdout=subprocess.PIPE)
    line = p.stdout.readline()
    while line:
        log.info(line)
        if re.match("\S+\s+device", line):
            break
        line = p.stdout.readline()
    else:
        raise AssertionError, "Device not connected via USB"


    driver = webdriver.Chrome(desired_capabilities=capabilities)
    return driver

此处a =_launch_android() b = _launch_android() a.get("https://www.google.com") b.get("https://www.facebook.com") 有效但b.get没有。

0 个答案:

没有答案