Turn from: 50013159
Directly on the code, note is based on the Chrome kernel browser, based on IE, please replace the chrome method for IE, but have not tried, if there is a result can be informed!
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 = Options ()
Chrome_options.binary_location = __browser_url
Driver = Webdriver. Chrome (chrome_options=chrome_options)
Driver.get (' http://www.baidu.com ')
driver.find_element_by_id ("kw"). Send_keys ("SELENIUMHQ" + Keys.return)
Time.sleep (3)
Driver.quit ()
The above is used directly, if you think in the test framework so that the use of dynamic, you can do a layer of encapsulation;
1. Add a line to the __init__.py file in this directory C:\Python27\Lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver
From. Chrome360.webdriver Import Webdriver as Chrome360
2, also add a directory under the directory: Chrome360, under which a new 2 files, __init__.py file can be empty, webdriver.py file content is as follows:
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)
This allows us to invoke it directly in the Webdriver object, as follows:
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 ()
This is similar to the code that calls other browsers
PS: Also you can do a py install patch package, so that when the environment, the installation of the patch will be used directly.
The Chromedriver.exe file must be installed, the Chromedriver.exe file must be installed, the Chromedriver.exe file must be installed, and the 360 browser
How to test 360 chrome kernel-based browsers in Python selenium