Webdriver.chrome not opening chrome



我正在编写一个自动化脚本,并试图在chrome中打开一个url,我已经安装并导入了selenium,下载了chrome驱动程序,并将其移动到/usr/local/bin。

但是,当我尝试运行脚本时,控制台是空白的,大约一秒钟后,它显示"进程已完成,退出代码为0",就好像什么都没发生一样。以下是我当前的代码:

from selenium import webdriver

class Script():
def __init__(self):
self.driver = webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver')
def login(self):
self.driver.get('https://facebook.com')

此处的路径错误。应该如下webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver.exe')需要在executable_path中添加.exe扩展名。此外,请确保您使用的是适用于Google chrome的chrome驱动程序的正确版本。

您使用的是linux系统。您不需要原始,即r开关。您的有效代码行将是:

self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')

这行得通吗?

from config import keys
from selenium import webdriver
def order():
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
driver.get('https://facebook.com')
print("here")
if __name__== '__main__':
order()

退出代码0表示运行时没有出现错误。如果发生错误,它将提供一个非零参数。我会添加一个

from selenium import webdriver

class Script():
def __init__(self):
self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
def login(self):
self.driver.get('https://facebook.com')
print ('Opened facebook')

这应该返回"Opened facebook",然后返回"Process finished with exit code 0"。我建立了类似的东西,将用户登录到Facebook。

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
class Script():
def __init__(self):
self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
def login(self):
self.driver.get('https://facebook.com')
print ('Opened facebook')       
self.driver.implicitly_wait(30)
self.driver.get(k['product_url'])
print ('Opened facebook')
username_box = self.driver.find_element_by_id('email')
username_box.send_keys('EMAIL ADDRESS')
print ('Email Id entered')
password_box = self.driver.find_element_by_id('pass')
password_box.send_keys('password')
print ('Password entered')
login_box = self.driver.find_element_by_id('loginbutton')
login_box.click()
print('Logged In')

最新更新