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

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

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

Google Chromeは携帯、テレビ、デスクトップなどの様々なプラットフォームで利用できるウェブブラウザです。Googleが開発したもので、Blink (レンダリングエンジン) とアプリケーションフレームワークを使用しています。

Python 3.x

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

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Python

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

selenium

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

Q&A

解決済

1回答

6307閲覧

SeleniumでJavascriptの検索フォームが動作しません(Python3)

G350

総合スコア13

Chrome

Google Chromeは携帯、テレビ、デスクトップなどの様々なプラットフォームで利用できるウェブブラウザです。Googleが開発したもので、Blink (レンダリングエンジン) とアプリケーションフレームワークを使用しています。

Python 3.x

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

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Python

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

selenium

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

0グッド

0クリップ

投稿2019/08/11 05:02

前提・実現したいこと

Seleniumを利用し、JKKのウェブサイトを自動操作したいです、
こちらがJKKのサイトです。
https://jhomes.to-kousya.or.jp/search/jkknet/service/akiyaJyoukenStartInit

上記ページで特定地域のチェックボックスをクリックし、「検索ボタン」をクリックしても
チェックボックスにチェックが入らず、検索ボタンクリック後の画面遷移も動作しません。

問題の箇所

Python3

1 def test_jkk2(self): 2 driver = self.driver 3 driver.get("https://jhomes.to-kousya.or.jp/search/jkknet/service/akiyaJyoukenStartInit") 4 5 # 以下の処理が全部動作しません。 6 7 # 市郡のチェックボックスをクリック 8 driver.find_element_by_xpath('//*[@id="chk_si_all"]').click() 9 10 # 検索ボタンをクリック、その1 11 driver.find_element_by_name("Image1").click() 12 13 # 検索ボタンをクリック、その2 14 driver.execute_script('javascript:submitPage("akiyaJyoukenRef")') 15 16

発生している問題・エラーメッセージ

#チェックボックスクリックのエラー Traceback (most recent call last): File "jkk.py", line 26, in test_jkk2 driver.find_element_by_xpath('//*[@id="chk_si_all"]').click() File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element 'value': value})['value'] File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/anaconda3/lib/python3.6/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":"xpath","selector":"//*[@id="chk_si_all"]"} (Session info: chrome=76.0.3809.100) #検索ボタンのクリック、その1のエラー Traceback (most recent call last): File "jkk.py", line 28, in test_jkk2 driver.find_element_by_name("Image1").click() File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 496, in find_element_by_name return self.find_element(by=By.NAME, value=name) File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element 'value': value})['value'] File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/anaconda3/lib/python3.6/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":"css selector","selector":"[name="Image1"]"} (Session info: chrome=76.0.3809.100) #検索ボタンのクリック、その2のエラー Traceback (most recent call last): File "jkk.py", line 29, in test_jkk2 driver.execute_script('javascript:submitPage("akiyaJyoukenRef")') File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 636, in execute_script 'args': converted_args})['value'] File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/anaconda3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.JavascriptException: Message: javascript error: submitPage is not defined (Session info: chrome=76.0.3809.100)

全体のソース

Python3

1from selenium import webdriver 2from selenium.webdriver.common.by import By 3from selenium.webdriver.common.keys import Keys 4from selenium.webdriver.support.ui import Select 5from selenium.common.exceptions import NoSuchElementException 6from selenium.common.exceptions import NoAlertPresentException 7import unittest, time, re 8 9class Jkk2(unittest.TestCase): 10 def setUp(self): 11 self.driver = webdriver.Chrome() 12 self.driver.implicitly_wait(30) 13 self.base_url = "https://www.katalon.com/" 14 self.verificationErrors = [] 15 self.accept_next_alert = True 16 17 def test_jkk2(self): 18 driver = self.driver 19 driver.get("https://jhomes.to-kousya.or.jp/search/jkknet/service/akiyaJyoukenStartInit") 20 driver.find_element_by_xpath('//*[@id="chk_si_all"]').click() 21 driver.find_element_by_name("Image1").click() 22 driver.execute_script('javascript:submitPage("akiyaJyoukenRef")') 23 24 25 def is_element_present(self, how, what): 26 try: self.driver.find_element(by=how, value=what) 27 except NoSuchElementException as e: return False 28 return True 29 30 def is_alert_present(self): 31 try: self.driver.switch_to_alert() 32 except NoAlertPresentException as e: return False 33 return True 34 35 def close_alert_and_get_its_text(self): 36 try: 37 alert = self.driver.switch_to_alert() 38 alert_text = alert.text 39 if self.accept_next_alert: 40 alert.accept() 41 else: 42 alert.dismiss() 43 return alert_text 44 finally: self.accept_next_alert = True 45 46 def tearDown(self): 47 self.driver.quit() 48 self.assertEqual([], self.verificationErrors) 49 50if __name__ == "__main__": 51 unittest.main() 52

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

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

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

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

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

guest

回答1

0

自己解決

すみません、自己解決いたしました。
こちらのサイトを参考に、複数タブが開かれる場合の処理を加えたところ動作しました。
https://www.seleniumqref.com/api/python/window_get/Python_window_handles.html

投稿2019/08/12 13:56

G350

総合スコア13

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問