PYTHON+SELENIUM2 automatic test of IE, Chrome browser launch

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.