question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Continue to allow access to _table_element_finder class

See original GitHub issue

Per 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:closed
  • Created 6 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
pekkaklarckcommented, Sep 23, 2017

@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.

1reaction
aaltatcommented, Sep 23, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restrict data input by using validation rules - Microsoft Support
A validation rule is one way to restrict input in a table field or a control (such as a text box) on a...
Read more >
Access 2013: Working with Tables - GCF Global
In Access tables are arguably the most important object. Use tables in Access to store all of your data to run queries and...
Read more >
How To Access Elements in the DOM - DigitalOcean
In this tutorial, you will learn several ways to access elements in the DOM: by ID, class, tag, and query selectors. Overview. Here...
Read more >
Documentation: 15: 5.9. Schemas - PostgreSQL
A PostgreSQL database cluster contains one or more named databases. ... but the system can be configured to allow joe access to only...
Read more >
Traversing an HTML table with JavaScript and DOM Interfaces
You will learn how to create, access and control, and remove HTML elements dynamically. The DOM methods presented here are not specific to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found