2
votes

I want to use selenium webdriver methods in the robot framework library.

def custom_go_to
        driver = BuiltIn().get_library_instance('SeleniumLibrary')
        driver.go_to(url)

The above code from custom library works fine, but I want to use selenium method at the place of robotframework builtin library. When I try to use driver.get(url) it says

'SeleniumLibrary' object has no attribute 'get'

The custom library I created ERP.py looks like

class ERP: 
   @keyword
    def custom_go_to(self, url):
        driver = BuiltIn().get_library_instance('SeleniumLibrary')
        driver.get(url)

And Test Case looks like

***Settings***
Library  SeleniumLibrary
Library  path_to_lib/ERP.py

*** Variable ***
${BROWSER}  |  chrome
${URL}  |  facebook.com

***Test Cases***
Open the browser using an inbuilt keyword and go to a given URL using custom go to using EventFiringWebDriver.
     Open Browser |  about:blank  |  ${BROWSER}
     Custom Go To  |   ${URL}

How can I use Selenium webdriver methods inside the robot framework library?

4
Don't know what you are trying to achieve here, but the newest SeleniumLibrary does not have Get keyword... Please try again with an existing keyword.asprtrmp
I want to use all Selenium keywords inside the robotframework library. Like we do normally when we use Selenium with Python only.Divaksh
Still, there is no Get keyword in SeleniumLibrary...asprtrmp
Thank you for pointing me out, I just updated the question. I want to use webdriver methods. :)Divaksh
There's a quite good tutorial for Python and webdriver here: selenium-python.readthedocs.io/…asprtrmp

4 Answers

5
votes

The selenium library itself is not a webdriver object, it's just an instance of the SeleniumLibrary class. You need to get a reference to the driver, which is an attribute in the library.

def custom_go_to(url):
    selib = BuiltIn().get_library_instance('SeleniumLibrary')
    selib.driver.get(url)

For more information about interacting with SeleniumLibrary at a low level, see the document Extending SeleniumLibrary in the SeleniumLibrary git repository.

0
votes

'SeleniumLibrary' do not have get attribute. Please refer to Selenium Library Robot Framework for more info.

You should be using

Open Browser    ${LOGIN URL}    ${BROWSER}

Below is example from the link
Example

*** Settings ***
Documentation     Simple example using SeleniumLibrary.
Library           SeleniumLibrary

*** Variables ***
${LOGIN URL}      http://localhost:7272
${BROWSER}        Chrome

*** Test Cases ***
Valid Login
    Open Browser To Login Page


*** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}

0
votes

SeleniumLibrary have a "Get Element Attribute" keyword.

See documentation here: RobotFramework SeleniumLibrary Documentation

-1
votes

Reproduced this as well:

driver.get(url) produces AttributeError: 'SeleniumLibrary' object has no attribute 'get'

An error with an existing keyword, such as driver.go_to(url) produces a different error: No browser is open.

So, use existing keywords or make your own.