Once the build python+selenium2 automated Test environment is complete, you will need to test whether the version of selenium that supports Python supports running on different browsers . We are currently testing scripts on three of the most common browsers.
1, run the test script on IE browser, first need to download IEDriverServer.exe, put in the Internet Explorer installation directory and the same sibling directory, the script is as follows:
From Selenium.webdriver.common.keys import keysiedriver= "C:\Program files\internet Explorer\iedriverserver.exe" os.environ["Webdriver.ie.driver"] =iedriverdriver=webdriver. Ie (Iedriver) driver.get ("http://www.python.org") assert "Python" indriver.titleelem= driver.find_element_by_name ("q ") Elem.send_keys (" Selenium ") Elem.send_keys (Keys.return) assert"Google"Indriver.titledriver.close () Driver.quit ()
2, run the test script on the Chrome browser, first need to download ChromeDriver.exe, placed in the Chrome browser installation directory and the sibling directory, the script is as follows:
From selenium import Webdriver
From Selenium.webdriver.common.keys importkeyschromedriver= "C:\Program Files (x86) \google\chrome\application\ Chromedriver.exe "os.environ[" Webdriver.chrome.driver "] =chromedriverdriver=webdriver. Chrome (Chromedriver) driver.get ("http://www.python.org") assert "Python" indriver.titleelem= driver.find_element_by _name ("q") Elem.send_keys ("Selenium") Elem.send_keys (Keys.return) assert "Google" Indriver.titledriver.close () Driver.quit ()
3. Run the test script on the Firefox browser, as follows:
From selenium import Webdriver
From Selenium.webdriver.common.keys Importkeysdriver=webdriver. Firefox () driver.get ("http://www.python.org") assert "Python" indriver.titleelem= driver.find_element_by_name ("Q") Elem.send_keys ("Selenium") Elem.send_keys (Keys.return) assert "Google" Indriver.titledriver.close () Driver.quit ()
Summary: Using the tests on the three different browsers above, the selenium in Python is the same as the Java version. Since Firefox is the default installation path, Webdriver can find him normally, if not the default installation path, you need to set the driver path with IE and chrome. Actually directly put the driver driver into the corresponding browser's default installation path, and then set path to that path, you can start successfully, but pay attention to the case of the call when the problem, such as Webdriver. Ie (), absolutely cannot write webdriver.ie (), otherwise it will error: module is not callable
PYTHON+SELENIUM2 automatic test of IE, Chrome browser launch