lost and found ( for me ? )

Splinter 0.6 : web test framework

Here are trial and error logs when installing splinter.

Reference
http://splinter.cobrateam.info/

# tail -1 /etc/lsb-release ;uname -ri
DISTRIB_DESCRIPTION="Ubuntu 13.10"
3.11.0-17-generic x86_64

# apt-get install python-pip

install splinter
# pip install splinter
Downloading/unpacking splinter
 Downloading splinter-0.6.0.tar.gz
 Running setup.py egg_info for package splinter
   
   no previously-included directories found matching 'tests'
Downloading/unpacking selenium>=2.39.0 (from splinter)
 Downloading selenium-2.40.0.tar.gz (2.5MB): 2.5MB downloaded
 Running setup.py egg_info for package selenium
   
Installing collected packages: splinter, selenium
 Running setup.py install for splinter
   
   no previously-included directories found matching 'tests'
 Running setup.py install for selenium
   
Successfully installed splinter selenium
Cleaning up...

access to google and enter “ubuntu” in the search bar, and then click “Google Search” button.

check the “Google search” button name..
Seen from www.google.com html file, it shows : "Google Search" name="btnG"

# cat access_google.py
#!/usr/bin/env python

from splinter import Browser

with Browser() as browser:
   url = "http://www.google.com"
   browser.visit(url)
   browser.fill('q', 'ubuntu')
   button = browser.find_by_name('btnG')
   button.click()
   if browser.is_text_present('www.ubuntu.com'):
       print "found"
   else:
       print "no"

run the script.
error
# ./access_google.py
Traceback (most recent call last):
 File "./access_google.py", line 10, in <module>
   button.click()
 File "/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/__init__.py", line 364, in click
   self._element.click()
 File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 59, in click
   self._execute(Command.CLICK_ELEMENT)
 File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 369, in _execute
   return self._parent.execute(command, params)
 File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 164, in execute
   self.error_handler.check_response(response)
 File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
   raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:
   at fxdriver.preconditions.visible (file:///tmp/tmppwWKeB/extensions/fxdriver@googlecode.com/components/command_processor.js:8225)
   at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmppwWKeB/extensions/fxdriver@googlecode.com/components/command_processor.js:10861)
   at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmppwWKeB/extensions/fxdriver@googlecode.com/components/command_processor.js:10878)
   at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmppwWKeB/extensions/fxdriver@googlecode.com/components/command_processor.js:10883)
   at DelayedCommand.prototype.execute/< (file:///tmp/tmppwWKeB/extensions/fxdriver@googlecode.com/components/command_processor.js:10825)

Googling this error, it seems that Firefox driver is buggy..

I will use chrome driver to confirm if this is caused by firefox driver.

To use chrome driver, install selenium at first.

# pip install selenium

I am using Ubuntu 13.10 64bit, so I downloaded the driver for 64bit.

unzip the file and copy the unzipped file to /usr/bin.
# unzip chromedriver_linux64.zip
Archive:  chromedriver_linux64.zip
 inflating: chromedriver     

# file chromedriver
chromedriver: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x281280cab9d7056c077166e1df52ceb2a51a578f, stripped

# cp chromedriver /usr/bin/

use chrome driver.
# cat access_google_02.py
#!/usr/bin/env python

from splinter import Browser

with Browser('chrome') as browser:
   url = "http://www.google.com"
   browser.visit(url)
   browser.fill('q', 'ubuntu')
   button = browser.find_by_name('btnG')
   button.click()
   if browser.is_text_present('www.ubuntu.com'):
       print "found"
   else:
       print "no"

Okay!
This error seems to be caused by firefox driver.
# ./access_google_02.py
found

similar script. search “ubuntu”
# cat access_google.py
#!/usr/bin/env python

from splinter import Browser

url = "http://www.google.com"
   
browser = Browser('chrome')
browser.visit(url)
browser.fill('q', 'ubuntu')
browser.find_by_name('btnG').first.click()
   
if browser.is_text_present('www.ubuntu.com'):
   print "found"
else:
   print "no"
   
browser.quit()

# ./access_google.py
found

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.