1

I'm new to robotframework

I'd like to make some functions that aren't in the standard selenium2library

1) How to get driver to use in my functions?

2) How to use _element_find function (from Selenium2Library/keywords/_element.py) inside the library? (I tried to import mostly everything and still _element_find is out of reach)

class page(object):
    def __init__(self, driver=None, title=None, url=None):
        self._driver = driver
        self._title = title
        self._url = url

def get_driver(self):
    return self._driver

def wait_for_visibility(self, locator, info="no error", timeout=10):
    return WebDriverWait(self.get_driver(), timeout).until(
        expected_conditions.visibility_of_element_located(locator), info)

def find_element(self, locator):
    return self.get_driver().find_element(*locator)

def clear_field(self, locator):
    self.find_element(locator).clear()

def send_keys(self, value_to_send, locator, info="field was not visible"):
    self.wait_for_visibility(locator, info)
    self.find_element(locator).send_keys(value_to_send)
    return self

def clear_field_and_send_keys(self, value_to_send, locator, info="field was not visible"):
    self.clear_field(locator)
    self.send_keys(value_to_send, locator, info)

def send_to_field_random_value_of_length(self, locator, leng, info="field was not visible"):
    self.clear_field(locator)
    value = rstr.rstr("abcdefghijklmnoprstuwxyz", leng)
    self.send_keys(value, locator, info)

def my_click(self, locator, info="click on button error", timeout=5):
    element = self.wait_for_visibility(locator, info, timeout)
    element.click()

then I'd like to use it for example this way:

Register Proper Data
    [Setup]    Open Browser ${web-page}    browser=${browser}
    my click  (By.PARTIAL_LINK_TEXT, "Zarejestruj nowe konto")
    send to field random value of length  (By.ID, "rejestracja_konta_imie")  7

is it a proper approach?

Now i get error AttributeError: 'NoneType' object has no attribute 'find_element'

3 Answers 3

2

What is a purpose of using Selenium2Library outside of Robot Framework? If you create your own Python library you should rather use pure Selenium Webdriver. To add some functions to existing Selenium2Library you should extend this class and create your own (for example JedrekSelenium2Library) containing new methods.

Sign up to request clarification or add additional context in comments.

Comments

2

i found the answer

from Selenium2Library import Selenium2Library

class page(Selenium2Library):

def get_driver(self):
    return self._current_browser()

the error i'm getting now: Python Robot Framework Pass arguments to a function can anyone help?

1 Comment

Good. You used inheritance. I suggest to rename class. Python classes should start with capital letter. I was trying to edit this but "edits must be at least 6 character long". What a strange requirement.
1

Your error is probably coming from return self.get_driver().find_element(*locator) in find_element.

Try to create a minimal working example and share so we can reproduce.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.