我使用linux下的網絡測試分裂(v0.7.3),而鉻,默認的示例代碼不能在運行:分裂:如何添加鉻選項?
from splinter import Browser
from pyvirtualdisplay import Display
d = Display(visible=0, size=(800, 600))
d.start()
b = Browser('chrome')
b.visit('http://www.google.com')
b.quit()
d.stop()
在運行時,我得到了這樣的例外:
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
我測試相同功能的硒與一些鍍鉻選項添加:
from selenium import web driver
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display
d = Display(visible=0, size=(800, 600))
d.start()
opt = Options()
opt.add_argument('--disable-setuid-sandbox')
b = webdriver.Chrome(chrome_options=opt)
b.get('http://www.google.com')
b.quit()
d.stop()
該工程確定,所不同的是--disable-setuid-sandbox
選項添加到鉻驅動程序,如果選項不添加,將有一個殭屍chrome-sandbox
進程chromium-browser
。
這裏的問題是,我不知道如何將chrome.options.Option
實例傳遞給splinter.Browser()
,我瀏覽了實施splinter/driver/webdriver/chrome.py
下,似乎沒有進入到這樣一個實例傳遞給splinter.Browser()
。有沒有其他方式可以將選項傳遞給Chrome驅動程序?
你能告訴我鏈接嗎?我搜索了[文檔](https://splinter.readthedocs.io/en/latest/index.html),有一個'desired_capabilities',但只適用於firefox,不幸的是,'chrome_options'不適用於我目前的分裂版本(0.7.3)。 – coanor
@coanor它在Remote WebDiver的文檔中(https://splinter.readthedocs.io/en/latest/drivers/remote.html)我認爲它不同於Chrome WebDriver,因爲它同時創建了一個同一瀏覽器類的實例。你有沒有嘗試我的建議? – RemcoW
@coanor以下是瀏覽器類的源代碼https://github.com/cobrateam/splinter/blob/master/splinter/browser.py。正如你所看到的,它只不過是創建一個ChromeWebDriver並傳遞* args和** kwargs。所以這意味着你可以傳遞由Selenium WebDriver使用的參數,該參數在https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/chrome/webdriver.py#L34 – RemcoW