def open_link_in_new_tab(self, elem): CONTROL_KEY = get_control_key() actions = ActionChains(self.driver) actions.move_to_element(elem) actions.key_down(CONTROL_KEY) actions.click(elem) actions.key_up(CONTROL_KEY) actions.perform()
def open_link_in_new_tab(self, elem): CONTROL_KEY = get_control_key() actions = ActionChains(self.driver) actions.move_to_element(elem) actions.key_down(CONTROL_KEY) actions.click(elem) actions.key_up(CONTROL_KEY) actions.perform()
def browse_match_reports(self, elements): """ Browses match reports one by one :param elements: list of elements which are links to match reports :type elements: """ # Get control key based on system platform CONTROL_KEY = get_control_key() for elem in elements: # If batch size is zero that means all fixtures have been browsed, so return if self.batch_size == 0: break # Skip if required if self.skip != 0: self.skip -= 1 continue # Save the window opener (current window, do not mistaken with tab... not the same) main_window = self.browser.current_window_handle() # Open match report in new tab self.browser.open_link_in_new_tab(elem) # Sleep for 5s time.sleep(5) # Switch tab to the new tab, which we will assume is the next one on the right self.browser.find_element_by_tag_name('body').send_keys( Keys.CONTROL + Keys.TAB) # Put focus on current window which will, in fact, put focus on the current visible tab self.browser.switch_to_window(main_window) # Check for forbidden access server_response = normalize( self.browser.find_element_by_css_selector( "div[id='header']").text) if server_response == "Server Error": self.browser.quit() raise ForbiddenAccessError # Analyze the match report self.analyze_match_report() # Close current tab self.browser.find_element_by_tag_name('body').send_keys( CONTROL_KEY + 'w') # Put focus on current window which will be the window opener self.browser.switch_to_window(main_window) # Decrement batch size self.batch_size -= 1
def browse_match_reports(self, elements): """ Browses match reports one by one :param elements: list of elements which are links to match reports :type elements: """ # Get control key based on system platform CONTROL_KEY = get_control_key() for elem in elements: # If batch size is zero that means all fixtures have been browsed, so return if self.batch_size == 0: break # Skip if required if self.skip != 0: self.skip -= 1 continue # Save the window opener (current window, do not mistaken with tab... not the same) main_window = self.browser.current_window_handle() # Open match report in new tab self.browser.open_link_in_new_tab(elem) # Sleep for 5s time.sleep(5) # Switch tab to the new tab, which we will assume is the next one on the right self.browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB) # Put focus on current window which will, in fact, put focus on the current visible tab self.browser.switch_to_window(main_window) # Check for forbidden access server_response = normalize(self.browser.find_element_by_css_selector("div[id='header']").text) if server_response == "Server Error": self.browser.quit() raise ForbiddenAccessError # Analyze the match report self.analyze_match_report() # Close current tab self.browser.find_element_by_tag_name('body').send_keys(CONTROL_KEY + 'w') # Put focus on current window which will be the window opener self.browser.switch_to_window(main_window) # Decrement batch size self.batch_size -= 1