def test_selenium_v_d_s_a_orig(self): driver = self.driver driver.get(self.base_url + "/vdsa-login.aspx") driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtUserName").clear() driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtUserName").send_keys(USERNAME) driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtPWD").clear() driver.find_element_by_id("ctl00_ContentPlaceHolder1_txtPWD").send_keys(PASSWORD) Select(driver.find_element_by_id("ctl00_ContentPlaceHolder1_ddlSelect")).select_by_visible_text("Meso Data") driver.find_element_by_id("ctl00_ContentPlaceHolder1_btnSubmit").click() Select(driver.find_element_by_id("ctl00_ContentPlaceHolder1_DropDownList1")).select_by_visible_text("India") driver.find_element_by_css_selector("option[value=\"India\"]").click() print "You are logged into the Meso dataset for India" select = driver.find_element_by_id("ctl00_ContentPlaceHolder1_DropDownList2") #Captures state names options = select.find_elements_by_tag_name("option") optionsList = [] for option in options: optionsList.append(option.get_attribute("value")) for optionValue in optionsList: if optionValue != "--Select--": print "Downloading %s" % optionValue select = Select(driver.find_element_by_id("ctl00_ContentPlaceHolder1_DropDownList2")) select.select_by_value(optionValue) checkboxes = driver.find_elements_by_xpath("//input[@type='checkbox']") for checkbox in checkboxes: checkbox.click() driver.find_element_by_id("ctl00_ContentPlaceHolder1_RequestData").click() select = driver.find_element_by_id("ctl00_ContentPlaceHolder1_GridView1") #Captures all download links links = select.find_elements_by_tag_name("a") linksList = [] for link in links: linksList.append(link.get_attribute("value")) for x in range(0,len(linksList)): links[x].click() time.sleep(DELAY) time.sleep(DELAY) driver.find_element_by_link_text("Back").click()
def getDropdown(self, locator="", locatorType="id", droptext=""): element = None try: locatorType = locatorType.lower() byType = self.getByType(self, locatorType) element = Select(self.driver.find_element(byType, locator)) self.webScroll(self, direction='') for droptext in element.find_elements_by_tag_name(''): if droptext.text == '': droptext.select_by_visible_text('') break self.log.info("Element Found with locator: " + locator + " and locatorType: " + locatorType) except: self.log.info("Element not found with locator: " + locator + " and locatorType: " + locatorType) return element return droptext
time.sleep(1) driver.find_elements_by_class_name('btn.btn-info.btn-sm')[0].click() time.sleep(3) driver.find_element_by_class_name('btn.btn-success').click() time.sleep(2) driver.find_elements_by_class_name('btn.btn-info.btn-sm')[1].click() time.sleep(3) driver.find_element_by_class_name('btn.btn-success').click() time.sleep(2) #header a = driver.find_element_by_class_name('main-menu-navigation') time.sleep(2) a.find_elements_by_tag_name('li')[0].click() driver.implicitly_wait(10) b = driver.find_element_by_class_name('main-menu-navigation') time.sleep(2) b.find_elements_by_tag_name('li')[2].click() driver.implicitly_wait(10) c = driver.find_element_by_class_name('main-menu-navigation') time.sleep(2) c.find_element_by_xpath( "//a[contains(@href,'http://www.staging.laba360.t1t.in/casino.html')]" ).click() driver.implicitly_wait(10) d = driver.find_element_by_class_name('main-menu-navigation') time.sleep(2) d.find_element_by_xpath( "//a[contains(@href,'http://www.staging.laba360.t1t.in/sports.html')]"
def webscrape(username, password): parent = Tk() parent.withdraw() # This variable prevents the created therapy grid from being loaded into Python twice # in the event of an error therapy_grid_status = "Not loaded" # This initializes the selenium gecko webdriver and prevents it from creating logs browser = webdriver.Firefox(log_path='') browser.get('https://columbine.achievematrix.com/') # Subgoal 1: Getting the information to login to MatrixCare emailElem = browser.find_element_by_id('j_username') emailElem.send_keys(username) passwordElem = browser.find_element_by_id('j_password') passwordElem.send_keys(password) linkElem = browser.find_element_by_class_name('loginbtn') linkElem.click() # Attempts to login to MatrixCare # Subgoal 2: Navigating to report on MatrixCare. try: facility_elem = browser.find_element_by_name('facility_name') except: facility_elem = False if facility_elem: pass else: messagebox.showinfo('Error', 'The MatrixCare login information ' \ 'entered was incorrect. In a moment you will be' \ ' prompted to re-try.') browser.quit() parent.destroy() win32clipboard.OpenClipboard() therapy_grid_path_prep = win32clipboard.GetClipboardData() therapy_grid_path_prep = therapy_grid_path_prep.split(',') therapy_grid_path = therapy_grid_path_prep[0] win32clipboard.CloseClipboard() xl = win32com.client.Dispatch('Excel.Application') xl.DisplayAlerts = False xl.Workbooks.Open(therapy_grid_path) xl.Run('Import_Worksheet') therapy_grid_status = "Loaded" sys.exit() facility_elem.send_keys('Centre Avenue') search_elem = browser.find_element_by_name('search') search_elem.click() # Executes the search facility_elem = browser.find_element_by_link_text( 'CENTRE AVENUE HEALTH & REHAB - Ft. Collins, CO') facility_elem.click() reports_elem = browser.find_element_by_xpath('/html/body/nav[1]') action = ActionChains(browser) action.move_to_element(reports_elem) action.move_by_offset(-175, 0) action.click().perform() time.sleep(.5) reports_elem = browser.find_element_by_xpath( '//a[@href="/Zion?zionpagealias=REPORTMENUFACILITY"]') reports_elem.click() reports_elem = browser.find_element_by_id('ReportRadio202') reports_elem.click() reports_elem = browser.find_element_by_name('Submit') reports_elem.click() reports_elem = Select(browser.find_element_by_name('REPORTOUTPUTTYPE')) reports_elem.select_by_value('6') reports_elem = browser.find_element_by_name('StartDateOpenPeriod') reports_elem_value = reports_elem.get_attribute("value") reports_elem_value = datetime.strptime(reports_elem_value, '%m/%d/%Y') reports_elem_value = reports_elem_value - relativedelta(months=1) reports_elem_value = reports_elem_value.strftime('%m/%d/%Y') reports_elem.clear() reports_elem.send_keys(reports_elem_value) reports_elem = browser.find_element_by_name('EndDateOpenPeriod') reports_elem_value = reports_elem.get_attribute("value") reports_elem_value = datetime.strptime(reports_elem_value, '%m/%d/%Y') reports_elem_value = reports_elem_value reports_elem_value = reports_elem_value.strftime('%m/%d/%Y') reports_elem.clear() reports_elem.send_keys(reports_elem_value) reports_elem = browser.find_element_by_id('ResidentStatusMulti') for option in reports_elem.find_elements_by_tag_name('option'): if option.text == "Admission": option.click() ActionChains(browser).key_down(Keys.CONTROL) for option in reports_elem.find_elements_by_tag_name('option'): if option.text == "Return": option.click() ActionChains(browser).key_up(Keys.CONTROL) reports_elem = browser.find_element_by_name('Submit') reports_elem.click() time.sleep(13) #pyautogui.press('down') # Subgoal 3: Downloading report and importing into therapy record system # Data is pulled from the cliboard, which was sent by the Excel # VBA in order to find the therapy record file pyautogui.press('enter') time.sleep(5) browser.quit() if therapy_grid_status == "Not loaded": win32clipboard.OpenClipboard() therapy_grid_path_prep = win32clipboard.GetClipboardData() therapy_grid_path_prep = therapy_grid_path_prep.split(',') therapy_grid_path = therapy_grid_path_prep[0] win32clipboard.CloseClipboard() xl = win32com.client.Dispatch('Excel.Application') xl.DisplayAlerts = False xl.Workbooks.Open(therapy_grid_path) xl.Run('Import_Worksheet') sys.exit() else: xl.Run('Import_Worksheet') sys.exit()