1

I pulled this Python code from Selenium IDE export option and I replaced self.driver = webdriver.Firefox() with HtmlUnitDriver() but it doesn't work since I have an error :

AttributeError: 'module' object has no attribute 'HtmlUnitDriver'

The code is :

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class Scrape(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.HtmlUnitDriver()
        self.driver.setJavascriptEnabled(true)
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.google.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_scrape(self):
        driver = self.driver
....

Could you indicate me what I'm doing wrong ? I would like to use HtmlUnit instead of firefox to see if I can achieve my goal faster with less ressources. I would need to have Javascript activated if possible. If it is possible could you also tell me where I'm supposed to get those information from the documentation since I failed to find it ?

Wicelo
  • 2,358
  • 2
  • 28
  • 44
  • possible duplicate of [How do I use the HtmlUnit driver with Selenium through the Python bindings?](http://stackoverflow.com/questions/4081724/how-do-i-use-the-htmlunit-driver-with-selenium-through-the-python-bindings) – Beetle Dec 29 '14 at 12:50

1 Answers1

4

Not sure but AFAIK HtmlUnitDriver is only available if you're using the java version of webdriver. If you want to use htmlunit driver in python you need to start up the standalone server

java -jar selenium-server-standalone-x.x.x.jar 

And then connect to using via remote server

from selenium import webdriver
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNIT)
//or with enabled js
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS) 
Andrey Egorov
  • 1,249
  • 1
  • 12
  • 9