How do I use the HtmlUnit driver with Selenium through the Python bindings?

后端 未结 4 1218
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 08:41

I\'m using WebDriver through the Python bindings located on Google\'s site. According to the documentation here, it supports four browsers: Chrome, IE, Firefox, and HtmlUnit.

4条回答
  •  独厮守ぢ
    2021-02-01 08:52

    I use it like this:

    from selenium.remote import connect                                                                                                                          
    
    b = connect('htmlunit')                                                                                                                                      
    b.get('http://google.com')                                                                                                                                   
    
    q = b.find_element_by_name('q')                                                                                                                              
    q.send_keys('selenium')                                                                                                                                      
    q.submit()                                                                                                                                                   
    
    for l in b.find_elements_by_xpath('//h3/a'):                                                                                                                 
        print('%s\n\t%s\n' % (l.get_text(), l.get_attribute('href')))
    

提交回复
热议问题