1. Execute test case by Chrome
1.1.Create a [BrowersDriver] folder under Python36 folder.
1.2.Download Goolge WebDriver and save into BrowersDriver folder - link1 link2
(P.S : You can save it wherever you want. )
1.3. Create testChrome.py file in pyCharm IDE.
1.4. Entering the below code and execute it.
from selenium import webdriver url="C:\\Programs\\Python36\\BrowersDriver\\chromedriver.exe" driver=webdriver.Chrome(url) driver.get("http://www.google.com") # print current url print(driver.current_url) # print current page title print(driver.title) # Close the browser window that the driver has focus of driver.close() # Call Dispose() => Release all resource. driver.quit()
In this test case,
1. go to Google Website
2. print current URL - https://www.google.com.sg/?gfe_rd=cr&ei=FlbnWJ2QIrHG8AfLz7zQDg&gws_rd=ssl
3. print current webpage title - Google
4. close the browser
5. release webdriver.
PS: If your chrome just shows blank page, WebDriver you download does not support your Chrome.
Solution: download Chrome WebDriver which match your chrome version or
downgrade your chrome version.
My Chrome Version: 57.02987.133 (64 bit)
ChromeDriver.exe version is blank.
2. Browser Behavior
You will learn how to manipulate browser behavior - Go, back, forward, refresh.
2.1 Create a python file - TestDriverBehavior.py
2.2 Entering the below code and execute it.
In this test case,
1. go to Google Website
2. print current URL - https://www.google.com.sg/?gfe_rd=cr&ei=FlbnWJ2QIrHG8AfLz7zQDg&gws_rd=ssl
3. print current webpage title - Google
5. go to Yahoo website
6. print current URL - https://sg.yahoo.com/?p=us
7. print current webpage title -Yahoo
8. go back privous web page (Google)
9. print current URL - https://www.google.com.sg/?gfe_rd=cr&ei=FlbnWJ2QIrHG8AfLz7zQDg&gws_rd=ssl
10. print current webpage title - Google
11. go forward to next web page (Yahoo)
12. print current URL - - https://sg.yahoo.com/?p=us
13. print current webpage title - Yahoo
14. refresh current page
15. close the browser
16. release webdriver.
You can download my code on my github