Selenium Wire Chrome驱动程序失去了互联网连接

时间:2020-08-10 04:53:02

标签: python-3.x selenium selenium-chromedriver

我使用的是Mac OS(macOS Catalina 10.15.5),并且在/usr/local/bin/chromedriver上安装了chromedriver。

我正在使用以下代码。我面临的问题是chrome在会话之间失去了Internet连接。

import os

from selenium import webdriver
from seleniumwire import webdriver as wire_webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

profile_path ='/Users/doptimusprime/code/ProductionProfile/User_Data'
options = webdriver.ChromeOptions()
options = wire_webdriver.ChromeOptions()
options.add_argument("user-data-dir="+profile_path)
options.add_argument('profile-directory=Default')
#options.add_argument('headless')
#options.add_argument('no-sandbox')
#options.add_argument('disable-dev-shm-usage')

driver = wire_webdriver.Chrome(executable_path="/usr/local/bin/chromedriver",chrome_options=options)
wait = WebDriverWait(driver, 5)
driver.get('https://admin.booking.com')
user_id = wait.until(EC.presence_of_element_located((By.ID, "loginname")))
loginId = os.environ.get('LOGIN_ID')
password = os.environ.get('PASSWORD')
user_id.send_keys(loginId)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'#root > div > div.access-container.bui_font_body > div > div.access-panel.bui-spacer--large.box-shadow.nw-access-panel > div.transition-container > div > div > div > form > div.bui-spacer > button > span'))).click()
secretKey = wait.until(EC.presence_of_element_located((By.ID, "password")))
# AFTER THIS STEP, I AM LOSING INTERNET CONNECTION
secretKey.send_keys(password)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,
                                           '#root > div > div.access-container.bui_font_body > div > div.access-panel.bui-spacer--large.box-shadow.nw-access-panel > div.transition-container > div > div > div > form > button > span'))).click()

cookies = driver.get_cookies()
driver.implicitly_wait(10)
urlr = driver.current_url
print("url is " + urlr)

完成上述步骤后,我打开了一个新标签,并尝试打开google.com。它正在显示No Internet。我尝试禁用防火墙。问题仍然存在。

两者之间失去Internet连接的原因是什么?

编辑:似乎是硒线webdriver问题。没有电线,它工作正常。感谢@RahulL指出这一点。

0 个答案:

没有答案
相关问题