我正在编写一个自动化脚本,并尝试在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')发布于 2020-03-13 02:43:27
这里的路径是错误的。如下所示,webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver.exe')需要在executable_path中添加.exe扩展。此外,请确保您使用的是用于Google Chrome的正确版本的chrome驱动程序。
发布于 2020-03-13 02:48:03
这行得通吗?
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')发布于 2020-03-13 04:18:56
你不需要raw,也就是r开关。您的有效代码行将是:
self.driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')https://stackoverflow.com/questions/60660016
复制相似问题