前提
ConoHa WINGで、Seleniumを動かしたく、Webで先駆者のお手本を見ながらサンプルコードを動作させたところ(※1)、以下のエラーメッセージが発生して、自力では解決できずに長時間はまっております。
■バージョン
Python 3.6.15
selenium 3.141.0
Chromium 107.0.5304.0
ChromeDriver 107.0.5304.0
実現したいこと
- 発生しているエラーを解消したい
発生している問題・エラーメッセージ
Traceback (most recent call last): File "code/selenium_test.py", line 18, in <module> service=service, options=options, desired_capabilities=capabilities TypeError: __init__() got an unexpected keyword argument 'service'
該当のソースコード
python
1from selenium import webdriver 2from selenium.webdriver.common.by import By 3from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 4from selenium.webdriver.support import expected_conditions 5from selenium.webdriver.support.ui import WebDriverWait 6 7options = webdriver.ChromeOptions() 8options.add_argument("--headless") 9capabilities = DesiredCapabilities.CHROME.copy() 10capabilities["acceptInsecureCerts"] = True 11 12service = webdriver.chrome.service.Service( 13 # executable_path="C:\Program Files\Python310\chromedriver.exe" #自宅のPC環境用(正常終了) 14 executable_path="/home/cXXXXXXX/local/chromium1047731/chromedriver" 15) 16 17with webdriver.Chrome( 18 service=service, options=options, desired_capabilities=capabilities 19) as driver: 20 21 driver.get("https://www.electronjs.org/") 22 driver.implicitly_wait(30) 23 24 wait = WebDriverWait(driver, 30) 25 wait.until( 26 expected_conditions.visibility_of_element_located( 27 (By.CLASS_NAME, "jumbotron-lead") 28 ) 29 ) 30 31 driver.save_screenshot("screenshot_selenium.png")
試したこと
- ConoHa WING上ではなく、自宅のwindowsのPC環境上で、一部環境依存のパスのみ変えて実行した(変更箇所はコメントにしている箇所)。こちらでは正常終了した。
補足情報(FW/ツールのバージョンなど)
バージョンについては前提に記載しました。
ソースコード中のexecutable_pathを設定するところで、"cXXXXXXX"と伏字にしていますが、実行時には適切な値を設定して実行しています。
※1)参考にさせて頂いたのは下記サイトです。これと同じ事を実現したかったのです。
https://picscels.site/conoha-wing-chromium-selenium/

回答1件
あなたの回答
tips
プレビュー