from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

__browser_url = r'C:\Users\Administrator\AppData\Roaming\360se6\Application\360se.exe' ##360浏览器的地址chrome_options)

driver.get('http://www.baidu.com')
driver.find_element_by_id("kw").send_keys("seleniumhq" + Keys.RETURN)
time.sleep(3)
driver.quit()

先来个例子,见上:

chromedriver官方下载地址:http://chromedriver.storage.googleapis.com/index.html

上面是直接使用,如果你觉得在测试框架中这么用不方便动态使用的话,可以做一层封装,步骤见下:

1、C:\Python27\Lib\site-packages\selenium\webdriver这个目录中的__init__.py文件添加一行

from .chrome360.webdriver import

 

selenium中如何测试360等基于chrome内核的浏览器_python

 

 

2、同样在该目录下添加一个目录:chrome360,其下新建2个文件,__init__.py文件可以为空,webdriver.py文件内容如下:

from selenium.webdriver import Chrome as ChromeWebdriver
from selenium.webdriver.chrome.options import Options
import os

class WebDriver(ChromeWebdriver):

def __init__(self, b360bin=None, executable_path="chromedriver", port=0,chrome_options=None, service_args=None, desired_capabilities=None, service_log_path=None):
if b360bin:
self.bin = b360bin
else:
self.bin = r'%s\360Chrome\Chrome\Application\360chrome.exe' % os.getenv('LOCALAPPDATA') ##你也可以读注册表来获取360的安装位置
chrome_options = Options()
chrome_options.binary_location = self.bin
ChromeWebdriver.__init__(self, executable_path, port, chrome_options, service_args, desired_capabilities, service_log_path)

selenium中如何测试360等基于chrome内核的浏览器_chrome_02

3、这样我们就可以在webdriver对象中直接调用,方法如下:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Chrome360()
driver.get('http://www.baidu.com')
driver.find_element_by_id("kw").send_keys("seleniumhq" + Keys.RETURN)
time.sleep(3)
driver.quit()