Python Webdriver.chrome未打开chrome
我正在编写一个自动化脚本,并试图在chrome中打开一个url,我已经安装并导入了selenium,下载了chrome驱动程序,并将其移动到/usr/local/bin 但当我尝试运行脚本时,控制台是空白的,大约一秒钟后,它会显示“processfinished with exit code 0”,就好像什么也没发生一样。以下是我目前的代码:Python Webdriver.chrome未打开chrome,python,selenium,selenium-webdriver,chrome-web-driver,linux,Python,Selenium,Selenium Webdriver,Chrome Web Driver,Linux,我正在编写一个自动化脚本,并试图在chrome中打开一个url,我已经安装并导入了selenium,下载了chrome驱动程序,并将其移动到/usr/local/bin 但当我尝试运行脚本时,控制台是空白的,大约一秒钟后,它会显示“processfinished with exit code 0”,就好像什么也没发生一样。以下是我目前的代码: from selenium import webdriver class Script(): def __init__(self):
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(可执行文件路径=r'/usr/local/bin/chromedriver.exe')
需要在可执行文件路径中添加.exe扩展名。
另外,请确保您使用的是适用于Google chrome的chrome驱动程序的正确版本。这是否有效
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')
这将返回“打开的facebook”,然后返回“进程已完成,退出代码为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')
你在系统上。您不需要原始的,即r
开关。您的有效代码行将是:
self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
我以前尝试过,但在控制台中出现了相同的输出。我尝试了两个不同版本的chrome驱动程序,我使用的是chrome版本80,还尝试了80和79,但两个版本似乎都不起作用。简单的脚本应该是,
来自selenium import webdriver
导入时间driver=webdriver.chrome(可执行文件路径='chrome驱动程序放置的路径')
驱动程序。获取(“https://www.facebook.com)
time.sleep(2)#sleep time要查看浏览器
,因为您正在使用类和函数,请确保按预期调用它们。我正在调用它们,并尝试了许多不同的方法,但由于某些原因,它们都不起作用。非常感谢,但是,通过添加print语句并运行程序,与之前发生的情况相同,控制台中由于某种原因没有显示print语句。不幸的是,由于某种原因,这些方法都无法工作,我不确定问题出在哪里。我在回答中添加了(可执行文件路径='/usr/local/bin/chromedriver')。。。