admin管理员组

文章数量:1586202

直接上代码,注意是基于chrome内核的浏览器,基于ie的请替换其中的chrome方法为ie,但自己未尝试过,如果有结果可以告知!

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

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

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

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

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

from .chrome360.webdriver import WebDriver as Chrome360

2、同样在该目录下添加

本文标签: 内核浏览器测试Pythonselenium