我希望在腳本中將 webdriver 設定為無頭。我能夠以非無頭方式運行它,但是當我創建 Option() 的實體時,它說我缺少 1 個必需的位置引數:'value'
chrome_options = Options()
這是我在專案中遇到的問題的復制。
from selenium import webdriver
from webbrowser import Chrome
from ssl import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class PythonOrg():
def Setup(self):
self.chrome_options = Options()
self.chrome_options.add_argument("--headless")
# self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #not a headless
self.driver = webdriver.Chrome(options=chrome_options)
def GetLink(self):
driver = self.driver
driver.get('https://www.python.org')
print(driver.title)
driver.close()
inst = PythonOrg()
inst.Setup()
inst.GetLink()
注意:我是 Python 新手!
uj5u.com熱心網友回復:
您匯入了錯誤的匯入。
代替
from ssl import Options
它應該是
from selenium.webdriver.chrome.options import Options
uj5u.com熱心網友回復:
為 chrome_options 添加自我。
并使用 from selenium.webdriver.chrome.options import Options not from ssl import Options
from selenium import webdriver
from webbrowser import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class PythonOrg():
def Setup(self):
self.chrome_options = Options()
self.chrome_options.add_argument("--headless")
# self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #not a headless
self.driver = webdriver.Chrome(options=self.chrome_options)
def GetLink(self):
driver = self.driver
driver.get('https://www.python.org')
print(driver.title)
driver.close()
inst = PythonOrg()
inst.Setup()
inst.GetLink()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/507729.html
標籤:Python 硒网络驱动程序 硒铬驱动程序 ui-自动化 网络自动化
上一篇:發現結束python行程的問題
