Continue to allow access to _table_element_finder class
See original GitHub issuePer discussion with @pekkaklarck on the Slack group…
Essential Issue
Having created some Python helper functions, using the Selenium2Library, I have been able to leverage some of the private methods to accomplish some useful things for my testing framework. An example below shows a function get_column_number
which used to be able to return the column number of whatever (valid) column name was passed in:
from robot.libraries.BuiltIn import BuiltIn
def _get_sel2lib():
"""== Gets Current Selenium 2 Instance from Robot Framework ==
- Uses the Robot Framework API to get an object of the current Selenium 2 instance.
- This is an internal helper function only.
== Calling ==
| *Args* | [none] | |
| *Returns* | ``object`` | An object instance of the current Selenium 2 library.
| *Raises* | [none] | |
"""
return BuiltIn().get_library_instance('Selenium2Library')
def get_column_number(table_locator, col_text, loglevel='INFO'):
"""== Returns Number of Specified Column ==
Returns the number of the first column found which contains the ``col_text`` string.
- Does not require an exact match; if there is a column named ``Foobar`` and you input ``Foo`` then it will match.
=== Calling ===
| *Args* | ``table_locator`` (str) | The table locator containing the column whose number you desire. |
| | ``col_text`` (str) | The string of the column you want to locate. |
| *Returns* | ``int`` | Number of column containing string ``col_name``. |
| *Raises* | AssertionError | If ``col_name`` cannot be found in the table specified. |
=== Example in Robot ===
| ${column_number} = Get Column Number xpath=//*[@id="deviceListHeader"] Unsafe
"""
sel2lib = _get_sel2lib()
locators = sel2lib._table_element_finder._parse_table_locator(table_locator, 'header')
found_it = False
for locator in locators:
elements = sel2lib._element_finder.find(sel2lib._current_browser(), locator)
counter = 0
for element in elements:
counter += 1
if col_text in element.text:
output = counter
found_it = True
break
if found_it is False:
sel2lib.log_source(loglevel)
raise AssertionError("No column containing '{}' found in the table identified via {}!".format(col_text, table_locator))
return output
With the new SeleniumLibrary, I get an error: AttributeError: 'SeleniumLibrary' object has no attribute '_table_element_finder'
as that structure doesn’t exist as-is. I do notice, however, that in tableelementfinder.py there is a method named find_by_header
which I could leverage if I could access it.
General Request
Provide a means to access some of these methods to get more granular access to some of the inner workings of the Selenium library.
Issue Analytics
- State:
- Created 6 years ago
- Comments:23 (23 by maintainers)
Top GitHub Comments
@GLMeece It’s fine that libraries are used programmatically by other libraries or any other code. We just need to make the related APIs public and stable. Whenever you are using something that
_starts_with_an_underscore
there’s a risk that the API changes in the future. It’s great that Python doesn’t prevent you from using such private APIs, but you should acknowledge the risk. Probably the best idea would be submitting an issue and proposing making that part of the API stable. In the end the best solution might then be adding a new keyword that exposes the functionality directly to everyone.The PR #912 is now merged in master, which provides a fix for this problem. Therefore closing the issue.
@GLMeece if you want to try out the changes, then you can install from source, example like this: https://stackoverflow.com/questions/15268953/how-to-install-python-package-from-github