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

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

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

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

selenium

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

Q&A

解決済

1回答

634閲覧

seleniumでの要素の取得

umepon0626

総合スコア21

Python 3.x

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

selenium

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

0グッド

0クリップ

投稿2019/01/31 08:08

selenium初心者です。
https://g-kyoto.pref.kyoto.lg.jp/reserve_j/core_i/init.asp?SBT=1
の「利用目的から施設を選ぶ」の「スポーツ」の「バスケットボール」をクリックさせたくて
以下のコードを書きました。

python

1from time import sleep 2from selenium import webdriver 3 4driver = webdriver.Chrome(executable_path="C:\chromedriver_win32\chromedriver.exe") 5driver.get('https://g-kyoto.pref.kyoto.lg.jp/reserve_j/core_i/init.asp?SBT=1') 6sleep(10) 7select_sport = driver.find_element_by_link_text('バスケットボール') 8select_sport.click() 9#search_box = driver.find_element_by_name("q") 10#search_box.send_keys('ChromeDriver') 11#search_box.submit 12sleep(5) 13driver.quit() 14

すると以下のエラーが出ました。

devTools listening on ws://127.0.0.1:63698/devtools/browser/b72b7274-76e6-4e95-a930-f23c9d580f1e Traceback (most recent call last): File "auto.py", line 7, in <module> select_region = driver.find_element_by_link_text('バスケットボール') File "C:\Users\temec\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in find_element_by_link_text return self.find_element(by=By.LINK_TEXT, value=link_text) File "C:\Users\temec\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value'] File "C:\Users\temec\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\temec\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"バスケットボール"} (Session info: chrome=72.0.3626.81) (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17134 x86_64)

xpathやcssセレクタにもトライしましたが、結果はおなじでした。
解決策をお教えください。

状態
python3.7.2

お願いしますm(__)m

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

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

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

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

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

guest

回答1

0

ベストアンサー

python

1driver.get('https://g-kyoto.pref.kyoto.lg.jp/reserve_j/core_i/init.asp?SBT=1') 2 3frame = driver.find_elements_by_xpath("//frame")[0] 4driver.switch_to.frame(frame) 5 6select_sport = driver.find_element_by_link_text('バスケットボール') 7select_sport.click()

これで 如何でしょうか?

投稿2019/01/31 15:42

Reach

総合スコア733

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

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

umepon0626

2019/02/02 12:28

返信ありがとうございます! ありがとうございます!ちゃんと動きました!! これは公式リファレンスを読むと理解できるものでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問