AttributeError: 'function' object has no attribute 'find_element_by_id'

1,536 views
Skip to first unread message

Simbolla

unread,
Aug 8, 2017, 11:59:04 PM8/8/17
to robotframework-users

I have below code in my custom keword file(ex: sample.py")

'''
Created on Jul 25, 2017

@author: simbolla
'''

from robot.api import logger
from robot.libraries.BuiltIn import BuiltIn
from Selenium2Library import Selenium2Library
from selenium import webdriver
def myseleniumkeyword():
    logger.info("my logger", also_console = True)
    selenium = BuiltIn().get_library_instance('Selenium2Library')
    selenium._current_browser.find_element_by_id("lst-ib").send_keys("simba")
    btn=selenium._current_browser.find_element_by_name('btnK')
    selenium._current_browser.execute_script("arguments[0].click()",btn)
   

Robot festcase :

*** Settings ***
Library           Selenium2Library
Library           C:/Softwares/seleniumtest/selenium2/sample.py

*** Test Cases ***
sample
    Open Browser    http://www.google.com    ie
    Mykeword

*** Keywords ***
mykeword
    myseleniumkeyword

When I tried to use my custom library in robot testcase , its throwing me this error "AttributeError: 'function' object has no attribute 'find_element_by_id'" in the result.

please some body guide me what is the mistake I am doing here.

Stack : Windows 8 professional, Python 2.7.12 , robotframework 3.0.2 , robotframework -Selenium2Library 1.8.0 ,Robotframework-ride 1.5.2.1




Bryan Oakley

unread,
Aug 9, 2017, 8:11:51 AM8/9/17
to vino...@gmail.com, robotframework-users
The error is telling you the problem.  You're trying to call `find_element_by_id` on a function. selenium._current_browser is a function, not an object. 

Change your code to this:

    selenium._current_browser().find_element_by_id(...)

Notice the () after _current_browser.


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

simbolla13 .

unread,
Aug 11, 2017, 2:14:29 AM8/11/17
to Bryan Oakley, robotframework-users
Thanks Bryan , It worked

To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsubscrib...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages