1.最大化
maximize_window
1 # coding = utf-8 2 3 from selenium import webdriver 4 chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver" 5 browser = webdriver.Chrome(chromedriver) 6 7 browser.get(‘http:\\www.baidu.com‘) 8 browser.maximize_window() 9 browser.find_element_by_id(‘kw‘).send_keys(‘selenium‘) 10 browser.find_element_by_id(‘su‘).click() 11 12 browser.quit()
发现运行时候报错了:
selenium.common.exceptions.WebDriverException: Message: disconnected: unable to connect to renderer
(Session info: chrome=62.0.3202.94)
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)
就是chrome和chromedriver版本不对应。关键词检索了下,发现的原因。然后下载了个更新的版本
http://chromedriver.storage.googleapis.com/index.html?path=2.34/
替换下就运行OK了