Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 01_Navigate_Url.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from selenium import webdriver

# Create an instance of Firefox WebDriver
browser = webdriver.Firefox()
# browser = webdriver.Firefox(executable_path="C:\\geckodriver\\geckodriver.exe")
browser=webdriver.Firefox()

# KEY POINT: The driver.get method will navigate to a page given by the URL
browser.get('http://qxf2.com/selenium-tutorial-main')
Expand Down
5 changes: 4 additions & 1 deletion 03_Set_Dropdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
driver.get("http://qxf2.com/selenium-tutorial-main")

# KEY POINT: Identify the dropdown and click on it
dropdown_element = driver.find_element_by_xpath("//button[@data-toggle='dropdown']")
dropdown_element = driver.find_element_by_xpath("//button[contains(text(),'Gender')]")
# dropdown_element = driver.find_element_by_xpath("//button[@data-toggle='dropdown']")

dropdown_element.click()
# Sleep is one way to pause while the page elements load
time.sleep(1)

# KEY POINT: Locate a particular option and click on it
#driver.find_element_by_xpath("//form[@id='myform']/descendant::a[contains(text(),'Male']").click()
driver.find_element_by_xpath("//a[text()='Male']").click()
# Future tutorials cover explicit, implicit and ajax waits
time.sleep(3)
Expand Down
4 changes: 3 additions & 1 deletion 05_Click_Button.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
driver.get("http://qxf2.com/selenium-tutorial-main")

# KEY POINT: Locate the button and click on it
button = driver.find_element_by_xpath("//button[text()='Click me!']")
# button = driver.find_element_by_xpath("//button[text()='Click me!']")

button = driver.find_element_by_xpath("//button[@class='btn btn-danger btn-lg' and text()='Click me!']")
button.click()

# Pause the script to wait for page elements to load
Expand Down
14 changes: 11 additions & 3 deletions 06_Form_Validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,24 @@
5) Close the browser
"""
import time
import os
from selenium import webdriver

# Create an instance of IE WebDriver
driver = webdriver.Ie()
# Create an instance of MS Edge WebDriver
# dir = os.path.dirname(__file__)
# edge_path = dir + "\\msedgedriver.exe"
driver=webdriver.Ie()
# driver = webdriver.Edge(executable_path="C:\\Program Files (x86)\\MicrosoftWebDriver\\MicrosoftWebDriver.exe")
#driver=webdriver.Edge(executable_path="C:\\Users\\Rahul Bhave Qxf2\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts\\msedgedriver.exe")
# Maximize the browser window
driver.maximize_window()
# time.sleep(250)
# Navigate to Qxf2 Tutorial page
driver.get("http://qxf2.com/selenium-tutorial-main")


# Find the click me! button and click it
time.sleep(10)
button = driver.find_element_by_xpath("//button[text()='Click me!']")
button.click()
# Pause the script to wait for validation messages to load
Expand All @@ -35,7 +43,7 @@
# 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:
except Exception as e:
#This pattern of catching all exceptions is ok when you are starting out
result_flag = False
else:
Expand Down
4 changes: 2 additions & 2 deletions 07_Form_Submit_Success.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
time.sleep(3)
# Verify user is taken to Qxf2 tutorial redirect url
if (driver.current_url== 'https://qxf2.com/selenium-tutorial-redirect'):
print "Success"
print ("Success")
else:
print "Failure"
print("Failure")

# Close the browser
driver.close()
Expand Down
2 changes: 1 addition & 1 deletion 09_Count_Rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# KEY POINT: Find the tr elements in the table
rows = table.find_elements_by_xpath("//tbody/descendant::tr")
print "Total No of Rows: %d"%len(rows)
print ("Total No of Rows: %d" %len(rows))

# Pause the script for 3 seconds
time.sleep(3)
Expand Down
19 changes: 15 additions & 4 deletions 10_Table_Text.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,28 @@
result_data = []
# Go to each row and get the no of columns and the navigate to column
# Then get the text from each column
for i in xrange(0,len(rows)):
for i in range(0,len(rows)):
# Find no of columns by getting the td elements in each row
cols = rows[i].find_elements_by_tag_name('td')
cols_data = []
for j in xrange(0,len(cols)):
for j in range(0,len(cols)):
# Get the text of each field
cols_data.append(cols[j].text.encode('utf-8'))
#cols_data.append(cols[j].text.encode('utf-8'))

cols_data.append(cols[j].text.encode('utf-8')for cols[j] in cols_data[0].split(u' b'))
# cols_data.append(cols[j].text.encode('utf-8'))
# result_data.append(cols_data.decode('utf8'))
result_data.append(cols_data)




# Print the result list
print result_data
print(result_data)





# Pause the script for 3 sec
time.sleep(3)
Expand Down
10 changes: 5 additions & 5 deletions 11_Consolidated_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
result_data = []
# Go to each row and get the no of columns and the navigate to column
# Then get the text from each column
for i in xrange(0,len(rows)):
for i in range(0,len(rows)):
# Find no of columns by getting the td elements in each row
cols = rows[i].find_elements_by_tag_name('td')
cols_data = []
for j in xrange(0,len(cols)):
for j in range(0,len(cols)):
# Get the text of each field
cols_data.append(cols[j].text.encode('utf-8'))
result_data.append(cols_data)
# Print the result set
print result_data
print (result_data)

# Find the name field using xpath with id
name = driver.find_element_by_xpath("//input[@id='name']")
Expand Down Expand Up @@ -84,9 +84,9 @@

# Verify user is taken to Qxf2 tutorial redirect url
if (driver.current_url== 'http://qxf2.com/selenium-tutorial-redirect'):
print "Success"
print ("Success")
else:
print "Failure"
print ("Failure")

# Pause the script for 3 sec
time.sleep(3)
Expand Down