Get your Python installation path. Paste this command into the command prompt and run it:
python -c "import os, sys; print(os.path.dirname(sys.executable))"
Copy the path and navigate into that folder and run Selenium installer:
Run these commands:
1. cd YOUR_PYTHON_PATH_FROM_ABOVE_HERE
2. Scripts\\pip.exe install selenium
You should get
Successfully installed selenium-3.141.0 urllib3-1.25.10
If you run into any issues, try to solve them yourself.
OK, which browser will you run the tests in? We'll use Chrome for to get started. Install Chrome if you don't have it already.
Download Chrome driver for your version of Chrome into C:\\
folder.
Cool. You're doing great. Now for the fun part, ready? Open Sublime Text, press "Command" + N to create a new file and copy-paste this script:
import time
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class GoogleSearchTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome("C:\\chromedriver.exe")
def test_search_returns_expected_result(self):
driver = self.driver
driver.get("<http://www.google.com>")
search_text_field = driver.find_element_by_name("q")
search_text_field.send_keys("Let me google that for you")
self.wait_for(seconds=3)
search_text_field.send_keys(Keys.RETURN)
self.wait_for(seconds=3)
expected_result = "LMGTFY - Search Made Easy"
assert expected_result in driver.page_source
def wait_for(self, seconds=0):
time.sleep(seconds)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()