How do I use the HTMLUnit driver with Selenium from Python?

前端 未结 3 1311
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 03:46

How do I tell Selenium to use HTMLUnit?

I\'m running selenium-server-standalone-2.0b1.jar as a Selenium server in the background, and the latest Python bindings inst

3条回答
  •  伪装坚强ぢ
    2020-12-14 04:15

    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')))
    

提交回复
热议问题