I am trying to open chrome browser with selenium webdriver in python on Windows 7 but it hangs. Below is the code I used:
`
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import *
import time
from pprint import pprint
chromeOps = webdriver.ChromeOptions()
print "after chrome opts", chromeOps
print dir(chromeOps)
pprint(chromeOps)
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
print "after binary loc"
browser = webdriver.Chrome("C:\\Python27\\chromedriver.exe", chrome_options=chromeOps)
print "after browser", browser
print dir(browser)
browser.get("http://www.google.com")
`
Can you help me please? Thank you!
Remove:
chromeOps = webdriver.ChromeOptions()
print "after chrome opts", chromeOps
print dir(chromeOps)
pprint(chromeOps)
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
print "after binary loc"
See what happens now. When I instantiate chrome, i just set the path to the chromedriver and it works fine for me, also, might be a perms issue running the chrome driver in Python27, try moving that somewhere else as well
I made some changes, taking out the ChromeOpts, because I don't have that file on my PC, and it works for me. Make sure that you add the chromedriver to PATH
and you should be fine.
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import *
import time
from pprint import pprint
import os
chromedriver = "C:\Users\USER\AppData\Local\Google\Chrome\Application\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
print "after binary loc"
browser = webdriver.Chrome(chromedriver)
print "after browser", browser
print dir(browser)
browser.get("http://www.google.com")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.