import time import base64 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.common.exceptions import UnexpectedAlertPresentException from selenium.common.exceptions import NoAlertPresentException from selenium.common.exceptions import NoSuchElementException from selenium.webdriver import ActionChains import unittest, time, re from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import TimeoutException from selenium.webdriver.support.select import Select
driver = webdriver.Firefox(executable_path=r'C:\Users\ME\Documents\webdrivers\geckodriver.exe') driver.maximize_window() location = "http://InbMEEEME:12048/dat" location2 = "http://meeedat" actions = ActionChains(driver) try: driver.get(location2) element = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "component/main?")) ) time.sleep(30) except UnexpectedAlertPresentException: print "XSS - WAITING FOR THE SERVER CREDENTIALS " print("**********************************************") time.sleep(30) QAUSER = r"C:\Python27\da-testing-login-python\official-selenium-login\bdgcqauser.txt" with open(QAUSER, 'r') as psfile: for line in psfile: newuser = base64.b64decode(line) CQAUSERLOGIN = newuser DM_USER = CQAUSERLOGIN driver.find_element_by_id("LoginUsername").send_keys(DM_USER) CPASS = r"C:\Python27\da-testing-login-python\official-selenium-login\bdgcpss.txt" with open(CPASS, 'r') as psfile: for line in psfile: newpasswd = base64.b64decode(line) QAPASSWORD = newpasswd DM_PASSWORD = QAPASSWORD print("Using encrypted passord **************************************************") print("Creating encrypted Loging passwd*****************************************") driver.find_element_by_id("LoginPassword").send_keys(DM_PASSWORD) time.sleep(5) print("Validating Login in button and sending that info ") print("**********************************************") XPATH = "/html/body/form/div/div[3]/div/div[2]/button" BUTTON = driver.find_element_by_xpath("/html/body/form/div/div[3]/div/div[2]/button").click() time.sleep(30) wait = WebDriverWait(driver, 30) print("Switching to frame **********") iframe = WebDriverWait(driver, 20).until(lambda driver : driver.find_element_by_tag_name('frame')) driver.switch_to.frame(iframe) time.sleep(30) print("Switching to default content ") driver.switch_to.default_content() print("Handling frame sctions*& *Switching to { MainEx_view_0 Frame & Classic_browser_0 ") print("**********************************") driver.switch_to.frame(driver.find_element_by_id("MainEx_view_0")) driver.switch_to.frame(driver.find_element_by_id("Classic_browser_0")) print("Finding BrowserTree_0 Tree & Finding Indexing Management") print("**********************************") IndexMngmnt = driver.find_element_by_link_text("Indexing Management") if IndexMngmnt: print(IndexMngmnt.tag_name) print(IndexMngmnt.is_enabled) print(IndexMngmnt.is_selected) CLICK = IndexMngmnt.click() time.sleep(4) print("Index management accessed Successfully") print("************************ **********") time.sleep(5) S = "*****************************************************" print("Handling Indexing Agent and Servers status section ") print(S) print("Switching to the { default frame, MainEx_view_0, Classic_workarea Frame & to Form_content_0 in this order}") driver.switch_to.default_content() driver.switch_to.frame(driver.find_element_by_id("MainEx_view_0")) time.sleep(2) driver.switch_to.frame(driver.find_element_by_id("Classic_workarea_0")) time.sleep(2) driver.switch_to.frame(driver.find_element_by_id("Form_content_0")) time.sleep(2) print(S) print("All frames processed Successfully") print(S) print("Checking index process Status") IndagntServer = driver.find_element_by_xpath("/html/body/form/div/table/tbody/tr[4]/td[2]/a") if IndagntServer: print(S) print(IndagntServer.is_enabled) print(IndagntServer.is_selected) CLICK = IndagntServer.click() print(S) print("Successfully Openned index Status Window") time.sleep(2) print("Dsiaplaying Server Index status") print(S) try: actions = ActionChains(driver) CLASS = driver.find_element_by_id("IndexAgentServerList_0") if CLASS: TABLE = driver.find_element_by_tag_name("table") if TABLE: TRS = driver.find_element_by_tag_name("tr") if TRS: print(S) print("On the right Frame") INDSTATUS = driver.find_element_by_xpath("/html/body/form/div/div[4]/table/tbody/tr[3]/td[8]") STatus = driver.find_element_by_xpath('/html/body/form/div/div[4]/table/tbody/tr[3]/td[8]') print(STatus.text) except NoSuchElementException as err: print("Sorry Unable to locate Test elements Specified!!: Test Failed:: {}::".format(err)) print(S) print("THE END") print("Proceeding with index stopping section ") print("Right click Index Agent & Index servers to access Stop Agent info ") try: indline = driver.find_element_by_css_selector("#IndexAgentServerList_datagrid_0_2") actions = ActionChains(driver) actions.context_click(indline).perform() print("Right click Successful ***************") print("Stopping index Agent ****************") driver.find_element_by_xpath('//span[@class="menu"]/div').click() time.sleep(2) print("Going to Stopping index agent frame for confirmation in order to stop the agent") print("**************************************************************************") try: driver.switch_to.default_content() driver.switch_to.frame(driver.find_element_by_id("MainEx_view_0")) driver.switch_to.frame(driver.find_element_by_id("Classic_workarea_0")) driver.switch_to.frame(driver.find_element_by_id("Form_content_0")) driver.switch_to.frame(driver.find_element_by_xpath('/html/frameset/frame[1]')) driver.find_element_by_css_selector("button.buttonLink:nth-child(1)").text OKLINK = driver.find_element_by_css_selector("button.buttonLink:nth-child(1)") if OKLINK: driver.find_element_by_css_selector("button.buttonLink:nth-child(1)").click() print("Index Agent Successfully & Gracely Stopped") print("***************************************************") print("END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END") except Exception as ss: print('Not able to swith to Stop index Frame: msg {} '.format(ss)) except NoSuchElementException as err: print("Sorry element specified missing!! {} :".format(err)) except TimeoutException as ex: print (" Timeout waiting for window swith to index popup: error msg = {}::".format(ex)) except NoSuchElementException as bb: print("Element Specified (index) Missing : msg {} ".format(bb)) except TimeoutException as tmo: print (" Timeout waiting for action chains performance: error msg = {}::".format(tmo)) except Exception as ms: print('Not able to click the element: msg {} '.format(ms)) finally: print("Index Agent Successfully & Gracely Stopped") print("***************************************************") print("END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~END") time.sleep(30) driver.quit()