Drew Courtney
Drew Courtney

Reputation: 29

Selenium module calling error

I'm trying to write a script to log into a website and press a button, without opening a browser or some such. I keep getting an error when I try to setup my selenium remote case, I keep getting a TYPEERROR: 'module' object is not callable.

    # -*- coding: utf-8 -*-
import selenium
import unittest, time, re

class ClockInRemote(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*chrome", "http://signin/ess.aew/DEFAULT")
        self.selenium.start()

    def test_clock_in_remote(self):
        sel = self.selenium
        sel.open("/attendance/ess.aew/DEFAULT")
        sel.type("id=AE_BadgeID_ID", "1234")
        sel.type("id=AE_PIN_ID", "5678")
        sel.click("css=input[type=\"submit\"]")
        sel.wait_for_page_to_load("30000")
        self.failUnless(sel.is_text_present("Punch IN or OUT"))
        sel.click("id=ID_AE_PageActivity301q1")
        sel.wait_for_page_to_load("30000")

    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

This gives me the error:

======================================================================
ERROR: test_clock_in_remote (__main__.ClockInRemote)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\PyScripts\ClockInRemote.py", line 8, in setUp
    self.selenium = selenium("localhost", 4444, "*chrome", "http://signin/ess.aew/DEFAULT")
TypeError: 'module' object is not callable

----------------------------------------------------------------------
Ran 1 test in 0.011s

FAILED (errors=1)

Any help would be appreciated!

Upvotes: 0

Views: 233

Answers (1)

keepAlive
keepAlive

Reputation: 6665

When you do

# -*- coding: utf-8 -*-
import selenium
import unittest, time, re

class ClockInRemote(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium(...) #<----------------
        #[...]

know that the object on the RHS whose name is selenium is not a callable, i.e. it is not a function. Actually, it is a module. You cannot call a module. You cannot do selenium(...)

I guess that what you actually want is using the function defined in the module, and both have the same nam. SImply replace selenium(...) by selenium.selenium(...), I mean

class ClockInRemote(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium.selenium("localhost", 4444, "*chrome", "http://signin/ess.aew/DEFAULT")
        #[...]


If you get the following error

Traceback (most recent call last):
  [...]
AttributeError: 'module' object has no attribute 'selenium'

you may want to read this. Try this out

# -*- coding: utf-8 -*-
from selenium import selenium         #<----------------
import unittest, time, re

class ClockInRemote(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium(...) #<----------------
        #[...]

Update

You are using Selenium's version 3.+

As it reads here

The major change in Selenium 3.0 is we’re removing the original Selenium Core implementation and replacing it with one backed by WebDriver. This will affect all users of the Selenium RC APIs.

This is very likely the reason why your code is not working anymore. You have two solutions. Either you downgrade your version of selenium (which is rarely a good idea), or you must re-develop a new testing framework which works with this new version.

Upvotes: 1

Related Questions