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

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

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

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

3097閲覧

Seleniumが実行できない

EOU818

総合スコア45

Python 3.x

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2022/02/27 14:21

こんにちは、
今下記LINKの練習をしています。
https://www.youtube.com/watch?v=Eu3CojjLQL4&t=733s
動画中の11:38のところまで、指示の言う通りに入力しましたが、
最初に'WebDriver' object has no attribute 'find'という結果が出てきました。
下記LINK中のヒントで、xpathを使ってみましたが、失敗しましたが...
https://teratail.com/questions/243278
どこか間違ったのか教えていただきたくお願いいたします。

下は僕のコードです。

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome import service as fs chrome_service = fs.Service(executable_path=r"C:\Users\t-chang\Downloads\新しいフォルダー (5)\chromedriver.exe") driver = webdriver.Chrome(service=chrome_service) driver.implicitly_wait(10) driver.get("https://www.library.chiyoda.tokyo.jp/") schedule_el = driver.find_element_by_xpath('//div[@class="schedule-list01__text"]/span') print([s.text for s in schedule_el])

下は出てきた結果です。

PS C:\Users\t-chang\Downloads\新しいフォルダー (3)> & C:/Python310/python.exe "c:/Users/t-chang/Downloads/新しいフォルダー (3)/selenium1.py" DevTools listening on ws://127.0.0.1:61343/devtools/browser/cc891b48-922f-45df-8197-03db4d577de0 c:\Users\t-chang\Downloads\新しいフォルダー (3)\selenium1.py:24: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead schedule_el = driver.find_element_by_xpath('//div[@class="schedule-list01__text"]/span') Traceback (most recent call last): File "c:\Users\t-chang\Downloads\新しいフォルダー (3)\selenium1.py", line 24, in <module> schedule_el = driver.find_element_by_xpath('//div[@class="schedule-list01__text"]/span') File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 521, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1248, in find_element return self.execute(Command.FIND_ELEMENT, { File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 425, in execute self.error_handler.check_response(response) File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed from unknown error: web view not found (Session info: chrome=98.0.4758.102) Stacktrace: Backtrace: Ordinal0 [0x012669A3+2582947] Ordinal0 [0x011FA6D1+2139857] Ordinal0 [0x010F3A98+1063576] Ordinal0 [0x010DC440+967744] Ordinal0 [0x0113AD09+1355017] Ordinal0 [0x01147AD2+1407698] Ordinal0 [0x01138366+1344358] Ordinal0 [0x01115176+1200502] Ordinal0 [0x01116066+1204326] GetHandleVerifier [0x0140BE02+1675858] GetHandleVerifier [0x014C036C+2414524] GetHandleVerifier [0x012FBB01+560977] GetHandleVerifier [0x012FA8D3+556323] Ordinal0 [0x0120020E+2163214] Ordinal0 [0x01205078+2183288] Ordinal0 [0x012051C0+2183616] Ordinal0 [0x0120EE1C+2223644] BaseThreadInitThunk [0x765CFA29+25] RtlGetAppContainerNamedObjectPath [0x77D77A9E+286] RtlGetAppContainerNamedObjectPath [0x77D77A6E+238]

以上、よろしくお願いいたします

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

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

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

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

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

guest

回答2

0

ベストアンサー

対象の HTML 要素がレンダリングされる(visible な状態になる)まで待ちます。

python

1from selenium.webdriver.support.ui import WebDriverWait 2from selenium.webdriver.support import expected_conditions as EC 3 4 5driver.get("https://www.library.chiyoda.tokyo.jp/") 6 7xpath = '//span[@class="schedule-list01__text"]' 8WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.XPATH, xpath))) 9schedule_el = driver.find_elements_by_xpath(xpath) 10print([s.text for s in schedule_el]) 11 12driver.close() 13 14# 15['開館', '開館', '開館', '開館', '開館']

投稿2022/02/28 16:32

編集2022/02/28 16:33
melian

総合スコア19803

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

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

0

Message: no such window: target window already closed

がエラーの理由です。簡単な英語なので意味はわかりますよね?

あと、find_element_by_xpathfind_elements_by_xpathの書き間違いでしょうね。

投稿2022/02/27 14:48

otn

総合スコア84557

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問