Since the test work to be done at work is long and time-consuming, I also tried to study Python3
system-name | Target version / environment |
---|---|
OS | macOS sierra 10.12.5 |
browser | Chrome 59.0.3071.115 |
Python | 3.6.1 |
Selenium | 3.4.3 |
virtualenv | 15.1.0 |
ChromeDriver | 2.30 |
Basically, I referred to Official Document
Prepare a place to create an environment with virtualenv
$ cd Desktop
$ mkdir PythonEnv
$ cd PythonEnv
Create a virtual environment
$ virtualenv SeleniumPython
$ cd SeleniumPython
Install selenium with pip
$ pip install selenium
Collecting selenium
Downloading selenium-3.4.3-py2.py3-none-any.whl (931kB)
100% |████████████████████████████████| 942kB 622kB/s
Installing collected packages: selenium
Successfully installed selenium-3.4.3
Download ChromeDriver from ChromeDriver --WebDriver for Chrome
Place the unzipped files under the / usr / local / bin
folder (anything that is in the path looks good)
$ sudo mv chromedriver /usr/local/bin
Enter the created virtual environment
$ pwd
/Users/<User name>/Desktop/SeleniumPython
$ source bin/activate
Create the following Python file
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
Execute the created Python file
$ python python_org_search.py
Then Chrome will start automatically and the official Python page will be launched.
For the time being, I'm going to try Official Document 2. Getting Started.
Recommended Posts