Download Python

https://www.python.org/downloads/

Run the installer for your environment. This example uses version 2.7 for Windows.

Select options "All Users" and "Add Python.exe to PATH."

Download Selenium

C:\Users\Casey>pip install selenium
Collecting selenium
  Downloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)
    100% |████████████████████████████████| 911kB 2.2MB/s
Collecting urllib3 (from selenium)
  Downloading https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl (118kB)
    100% |████████████████████████████████| 122kB 344kB/s
Installing collected packages: urllib3, selenium
Successfully installed selenium-3.141.0 urllib3-1.24.1
                    
Pip is executed on the Windows terminal, not Python's.

Download Chrome Driver

https://sites.google.com/a/chromium.org/chromedriver/downloads

Extract the zip. Note the file location. You'll use it in the next step.

Import

    > from selenium import webdriver
                        

Open Chrome

    > driver = webdriver.Chrome("C:\\Your\\Path\\Here\\chromedriver_win32\\chromedriver.exe")
    > driver.get("http://www.caseycodes.com/blog")
                        

Query

    > input = driver.find_element_by_xpath("//input[@type='text']")
    > input.send_keys("essential git")
    > submit = driver.find_element_by_id("searchsubmit")
    > submit.click()
                        

Scrape Screen

    > results = driver.find_elements_by_class_name("entry-title")
    > result0 = results[0].text
                        

testDemo.py with Unittest

    import unittest
    import time
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
                        

Test Class

    class TestManager(unittest.TestCase):
    
        def setUp(self):
            driver = webdriver.Chrome('C:\Users\Casey\Downloads\chromedriver_win32\chromedriver.exe')
            driver.get("http://www.Google.com")
        
        def tearDown(self):
            driver.close()
    class TestTheAnswerToLife(TestManager):
        def runTest(self):
                        

Arrange

            expected_answer = "42"
                        

Act

            search_box = driver.find_element_by_xpath("//input[@title='Search']")
            search_box.send_keys("What is the answer to life the universe and everything?")
            # this is why you need to import Keys
            search_box.send_keys(Keys.ENTER)
            calculator = driver.find_element_by_xpath("//h2[text()='Calculator Result']/following-sibling::div[1]")
            all_txt = calculator.text
            lines = all_txt.split('\n')
            Google_said = lines[1]
            print Google_said
            time.sleep(10)
                        

Assert

            self.assertEqual(expected_answer == Google_said)
                        

Call Main

    if __name__ == '__main__':
    unittest.main()
                        

Run it

    C:\Users\Casey>python TestDemo.py -v
     
    runTest (__main__.TestTheAnswerToLife) ... ok
     
    ----------------------------------------------------------------------
    Ran 1 test in 15.080s
     
    OK