From 4b666faa2275a04bf34ea132fe236889d0d4479b Mon Sep 17 00:00:00 2001 From: "Rahul.Bhave" Date: Wed, 25 Sep 2019 14:47:47 +0530 Subject: [PATCH] Modified test files --- 01_Navigate_Url.py | 3 ++- 03_Set_Dropdown.py | 5 ++++- 05_Click_Button.py | 4 +++- 06_Form_Validation.py | 14 +++++++++++--- 07_Form_Submit_Success.py | 4 ++-- 09_Count_Rows.py | 2 +- 10_Table_Text.py | 19 +++++++++++++++---- 11_Consolidated_Test.py | 10 +++++----- 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/01_Navigate_Url.py b/01_Navigate_Url.py index 2e9cfc2..20ef18c 100644 --- a/01_Navigate_Url.py +++ b/01_Navigate_Url.py @@ -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') diff --git a/03_Set_Dropdown.py b/03_Set_Dropdown.py index ee3db4a..ceb51d7 100644 --- a/03_Set_Dropdown.py +++ b/03_Set_Dropdown.py @@ -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) diff --git a/05_Click_Button.py b/05_Click_Button.py index d0fb0fa..4cc1ae2 100644 --- a/05_Click_Button.py +++ b/05_Click_Button.py @@ -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 diff --git a/06_Form_Validation.py b/06_Form_Validation.py index e228088..a0787cc 100644 --- a/06_Form_Validation.py +++ b/06_Form_Validation.py @@ -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 @@ -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: diff --git a/07_Form_Submit_Success.py b/07_Form_Submit_Success.py index 6a21347..d2fc6b4 100644 --- a/07_Form_Submit_Success.py +++ b/07_Form_Submit_Success.py @@ -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() diff --git a/09_Count_Rows.py b/09_Count_Rows.py index 6fce7e0..962bde0 100644 --- a/09_Count_Rows.py +++ b/09_Count_Rows.py @@ -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) diff --git a/10_Table_Text.py b/10_Table_Text.py index 906fdd5..d1894f0 100644 --- a/10_Table_Text.py +++ b/10_Table_Text.py @@ -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) diff --git a/11_Consolidated_Test.py b/11_Consolidated_Test.py index a729bad..f4e9366 100644 --- a/11_Consolidated_Test.py +++ b/11_Consolidated_Test.py @@ -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']") @@ -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)