<s> import re <EOL> import pdb <EOL> import sys <EOL> from Selenium2Library import Selenium2Library <EOL> from Selenium2Library . locators . tableelementfinder import TableElementFinder <EOL> from Selenium2Library . keywords . _tableelement import _TableElementKeywords <EOL> from selenium import webdriver <EOL> from selenium . common . exceptions import WebDriverException <EOL> def do_monkeypatches ( ) : <EOL> """<STR_LIT>""" <EOL> def _make_phantomjs ( self , remote , desired_capabilities , profile_dir ) : <EOL> browser = None <EOL> tries = <NUM_LIT:0> <EOL> while not browser and tries < <NUM_LIT:6> : <EOL> try : <EOL> browser = self . _generic_make_browser ( webdriver . PhantomJS , <EOL> webdriver . DesiredCapabilities . PHANTOMJS , remote , desired_capabilities ) <EOL> except WebDriverException , e : <EOL> print "<STR_LIT>" + str ( e ) <EOL> browser = None <EOL> tries += <NUM_LIT:1> <EOL> if browser : <EOL> return browser <EOL> else : <EOL> raise WebDriverException ( "<STR_LIT>" ) <EOL> Selenium2Library . _make_phantomjs = _make_phantomjs <EOL> __old_tef_init = TableElementFinder . __init__ . __func__ <EOL> def __new_tef_init ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> __old_tef_init ( self , * args , ** kwargs ) <EOL> self . _locator_suffixes [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = [ '<STR_LIT>' ] <EOL> self . _locator_suffixes [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = [ '<STR_LIT>' ] <EOL> self . _locator_suffixes [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = [ '<STR_LIT>' ] <EOL> self . _locator_suffixes [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . _locator_suffixes [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> TableElementFinder . __init__ = __new_tef_init <EOL> def find_by_row ( self , browser , table_locator , row , content ) : <EOL> """<STR_LIT>""" <EOL> location_method = "<STR_LIT>" <EOL> if "<STR_LIT:->" == row [ <NUM_LIT:0> ] : <EOL> row = row [ <NUM_LIT:1> : ] <EOL> location_method = "<STR_LIT>" <EOL> locators = self . _parse_table_locator ( table_locator , location_method ) <EOL> locators = [ locator % str ( row ) for locator in locators ] <EOL> return self . _search_in_locators ( browser , locators , content ) <EOL> TableElementFinder . find_by_row = find_by_row <EOL> def find_by_col ( self , browser , table_locator , col , content ) : <EOL> """<STR_LIT>""" <EOL> location_method = "<STR_LIT>" <EOL> if "<STR_LIT:->" == col [ <NUM_LIT:0> ] : <EOL> col = col [ <NUM_LIT:1> : ] <EOL> location_method = "<STR_LIT>" <EOL> locators = self . _parse_table_locator ( table_locator , location_method ) <EOL> locators = [ locator % str ( col ) for locator in locators ] <EOL> return self . _search_in_locators ( browser , locators , content ) <EOL> TableElementFinder . find_by_col = find_by_col <EOL> def get_table_cell ( self , table_locator , row , column , loglevel = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> row = int ( row ) <EOL> row_index = row <EOL> if row > <NUM_LIT:0> : row_index = row - <NUM_LIT:1> <EOL> column = int ( column ) <EOL> column_index = column <EOL> if column > <NUM_LIT:0> : column_index = column - <NUM_LIT:1> <EOL> table = self . _table_element_finder . find ( self . _current_browser ( ) , table_locator ) <EOL> if table is not None : <EOL> rows = table . find_elements_by_xpath ( "<STR_LIT>" ) <EOL> if row_index >= len ( rows ) or row_index < <NUM_LIT:0> : <EOL> rows . extend ( table . find_elements_by_xpath ( "<STR_LIT>" ) ) <EOL> if row_index >= len ( rows ) or row_index < <NUM_LIT:0> : <EOL> rows . extend ( table . find_elements_by_xpath ( "<STR_LIT>" ) ) <EOL> if row_index < len ( rows ) : <EOL> columns = rows [ row_index ] . find_elements_by_tag_name ( '<STR_LIT>' ) <EOL> if column_index >= len ( columns ) or column_index < <NUM_LIT:0> : <EOL> columns . extend ( rows [ row_index ] . find_elements_by_tag_name ( '<STR_LIT>' ) ) <EOL> if column_index < len ( columns ) : <EOL> return columns [ column_index ] . text <EOL> self . log_source ( loglevel ) <EOL> raise AssertionError ( "<STR_LIT>" <EOL> % ( table_locator , str ( row ) , str ( column ) ) ) <EOL> _TableElementKeywords . get_table_cell = get_table_cell <EOL> old_set_trace = pdb . set_trace <EOL> def _set_trace ( ) : <EOL> for attr in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> setattr ( sys , attr , getattr ( sys , '<STR_LIT>' % attr ) ) <EOL> old_set_trace ( ) <EOL> pdb . set_trace = _set_trace </s>
