Selenium python API usage in Sikuli scripts

Asked by Geo kurian

Hi
I'm trying to run selenium python script through Sikuli IDE.

from selenium import selenium
i'm gettin an error for this import, which i mentioned below

[error] Error message: Traceback (most recent call last):
 File "D:\sikuli\temp\sikuli-tmp679350259731755112.py", line 3, in
 from Selenium.Selenium import *
ImportError: No module named Selenium

can anyone help to overcome this error.
if posssible give more details on running selenium python scripts in sikuli IDE.

Thanks

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

pls. post the content of sys.path and the exact statements you are using to.

Did you check, wether the Slenium Python support can be run in Jython environment?

Revision history for this message
Geo kurian (geo-kurian) said :
#2

path: C:\Program Files\Sikuli X\libs;C:\Program Files\Java\jre6\\bin
sikuli_home:C:\Program Files\Sikuli X\

This is the code

from __future__ import with_statement
from selenium import selenium
import unittest, time, re

class Untitled(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*chrome", "http://www.google.co.in/")
        self.selenium.start()

    def test_untitled(self):
        sel = self.selenium
        sel.open("about:home")
        self.assertEqual("Mozilla Firefox Start Page", sel.get_title())
        sel.type("id=searchText", "geo")
        sel.click("id=searchSubmit")
        sel.wait_for_page_to_load("30000")
        self.assertEqual("geo - Google Search", sel.get_title())
        sel.click("link=Geo tv | Geo News ")
        sel.wait_for_page_to_load("30000")
        self.assertEqual("Geo tv | Geo News ", sel.get_title())

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

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

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Looking into the Selenium docs at "Python Client Driver Configuration", I guess you have to do the following:

selDir = "path-to-folder-containing-selenium.py"
if not selDir in sys.path: sys.path.append(selDir)
import selenium

this replaces your
from selenium import selenium

the rest of your code seems ok

from __future__ import with_statement
is not needed, since already done by Sikuli internally.

Revision history for this message
Geo kurian (geo-kurian) said :
#4

Hi RaiMan
Thank you for your early response.

I copied the selenium.py file into sikuli folder, it works
But some selenium scripts still not executing, but its not showing any error on the ide.
I'm getting exceptions like

File "D:\sikuli\temp\sikuli-tmp4054055221103003418.py", line 30, in start
 sel.click("id=cp-sol")
 File ".\selenium.py", line 260, in click
 self.do_command("click", [locator,])
 File ".\selenium.py", line 191, in do_command
 raise Exception, data
Exception: ERROR Server Exception: sessionId should not be null; has this session been started yet?

Revision history for this message
Geo kurian (geo-kurian) said :
#5

Hi RaiMan
How the control changes between sikuli script and selenium script during execution.
is there any extra configuration required for executing a mixture of sikuli and selenium scripts.

Revision history for this message
RaiMan (raimund-hocke) said :
#6

If you are running a Python script using Sikuli (either in the IDE or from command line), the script is run with the bundled Jython 2.5.2 interpreter. The needed stuff to use Sikuli features is made available internally. Jython is needed to run Scripts in Python language accessing Sikuli features, because the kernel of Sikuli is made in Java.

So there is no "control changes between sikuli script and selenium script during execution". It is just Python scripts using features of Sikuli or Selenium as needed one after the other.

For the above mentioned exceptions (comment #4): I have no idea. Seems to be a Selenium Python problem (might be, because we are running in Jython). Has nothing to do with Sikuli as such.

Revision history for this message
daluu (cuuld) said :
#7

An alternative is to run Selenium and Sikuli through Java instead of the Sikuli IDE and Jython/Python.

Can you help with this problem?

Provide an answer of your own, or ask Geo kurian for more information if necessary.

To post a message you must log in.