forked from qxf2/selenium-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_Form_Validation.py
52 lines (42 loc) · 1.43 KB
/
06_Form_Validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Check for the presence of absence of page elements
DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2
AUTHOR: Avinash Shetty
Contact: [email protected]
SCOPE:
1) Launch Internet Explorer driver
2) Navigate to Qxf2 Tutorial page
3) Find the Click me! button and click on it
4) Check for the validation message
5) Close the browser
"""
import time
from selenium import webdriver
# Create an instance of IE WebDriver
driver = webdriver.Ie()
# Maximize the browser window
driver.maximize_window()
# Navigate to Qxf2 Tutorial page
driver.get("http://qxf2.com/selenium-tutorial-main")
# Find the click me! button and click it
button = driver.find_element_by_xpath("//button[text()='Click me!']")
button.click()
# Pause the script to wait for validation messages to load
time.sleep(3)
# KEY POINT: Check if the validation mesage for name field
try:
driver.find_element_by_xpath("//label[text()='Please enter your name']")
except Exception,e:
#This pattern of catching all exceptions is ok when you are starting out
result_flag = False
else:
result_flag = True
if result_flag is True:
print("Validation message for name present")
else:
print("Validation message for name NOT present")
# Close the browser window
driver.close()