質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

Q&A

0回答

1257閲覧

selenium python remoteでオプションが反映されない

navca

総合スコア44

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

0グッド

1クリップ

投稿2019/03/22 14:11

編集2022/01/12 10:55

編集
当初の題は「ドライバが起動できない」でしたが、そういう問題でなく、webdriver.Remoteでオプションが反映されないという問題だったので変更しました。
パッケージ化していないmanifest.jsonを含むディレクトリを拡張機能として読み込みたいのですが、通常起動だと

options = Options().add_argument('--load-extension{}'.format(r'C:\path\to\the\dir')) webdriver.Chrome(executable_path=executable_path, options=options)

で読み込めますが、

options = Options().add_argument('--load-extension{}'.format(r'C:\path\to\the\dir')) webdriver.Remote(command_executor=EXECUTOR, desired_capabilities=Desiredcapabilities.CHROME, options=options) または、 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities as dc capb = dc.CHROME.copy() capb['chromeOption'] = {'args':['--load-extension={}'.format(r'C:\path\to\the\dir')]} webdriver.Remote(command_executor=EXECUTOR, desired_capabilities=capb)

では起動自体はしますが、拡張は読み込めませんでした。
目的は、始めに呼び出されたスクリプトが終了しても、二回目に呼び出されたときに最初に起動したdriverを利用するためにdriverをpickleしたいのですが、remoteで立ちあげないとpickleできないからです。

編集終わり


selenium remoteでドライバが起動できません。
remoteサーバーは最新をダウンロードしました。selenium-server-standalone-3.141.59
起動済みです。
seleniumのバージョンは 3.141.0
windows10

https://stackoverflow.com/questions/30986816/how-to-create-python-selenium-chrome-webdriver-remote-with-current-user-data
↑こちらの回答者のコードを見るとあってそうですが駄目でした。

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium import webdriver from selenium.webdriver.chrome.options import Options import traceback try:       unpacked_extension_path = パス options = Options() options = options.to_capabilities('--load-extension={}'.format(unpacked_extension_path)) driver = webdriver.Remote(command_executor=EXECUTOR, desired_capabilities=options) with open('pdriver', mode='wb') as f: pickle.dump(driver, f) except: import traceback traceback.print_exc() print('ドライバ起動失敗')
Traceback ~~~~~~~~~~~~~~~~~~~~~ raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: Unable to create session from { "desiredCapabilities": { }, "capabilities": { "firstMatch": [ { } ] } } Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: 'DESKTOP-Q4K164I', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201' Driver info: driver.version: unknown Stacktrace: at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4 (NewSessionPipeline.java:76) at java.util.Optional.orElseThrow (None:-1) at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5 (NewSessionPipeline.java:75) at java.util.Optional.orElseGet (None:-1) at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession (NewSessionPipeline.java:73) at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute (BeginSession.java:65) at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0 (WebDriverServlet.java:235) at java.util.concurrent.Executors$RunnableAdapter.call (None:-1) at java.util.concurrent.FutureTask.run (None:-1) at java.util.concurrent.ThreadPoolExecutor.runWorker (None:-1) at java.util.concurrent.ThreadPoolExecutor$Worker.run (None:-1) at java.lang.Thread.run (None:-1)

https://stackoverflow.com/questions/47075624/how-to-add-selenium-chrome-options-to-desiredcapabilities
↑こちらではoptions.to_capabilities()にしてからオプションを追加しています。
remoteサーバーでの起動は、どのサンプルを見てもchromedriverのパスの指定が無いので、オプションを指定することでブラウザの種類を指定してる?と思いやってみましたが。ダメでした。

options.to_capabilities() to get the capabilities from the options: options = webdriver.ChromeOptions() capabilities = options.to_capabilities() driver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=capabilities)
capabilities = options.to_capabilities() AttributeError: 'NoneType' object has no attribute 'to_capabilities'

chromedriverのパスの指定はchromedriverパスが通ている場合はいらない?ということなのでパスを通して再起動しましたが駄目でした。
よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問