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

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

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

URL(ユニフォームリソースロケータ)とは、インターネット上のリソース(Webページや電子メールの宛先等)を特定するための形式的な記号の並びの事を言う。

Python

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

Q&A

1回答

2444閲覧

ElementClickInterceptedException のエラー対応をtry,exceptで実装するもエラーが出ます。Python

Ju.-.

総合スコア0

URL

URL(ユニフォームリソースロケータ)とは、インターネット上のリソース(Webページや電子メールの宛先等)を特定するための形式的な記号の並びの事を言う。

Python

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

0グッド

0クリップ

投稿2021/08/09 14:18

前提・実現したいこと

instagramの投稿のurlを「リンクをコピーする」のボタンからコピーしてExcelに貼り付けるコードを書いています。
forループで回していたところ、「リンクをコピーする」ボタンを押した後に、さらにもう一段階「リンクをコピーする」ボタンを要求されることがあります。

1.「リンクをコピーする」→次の投稿へ行くボタン これが一段階でコピー出来た場合

2.「リンクをコピーする」→次の投稿へ行くボタン ここでエラーが発生したらもう一段階の「リンクをコピーする」を要求されたと認識させるような手順でいこうとコードを書いています。

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

ElementClickInterceptedException Traceback (most recent call last) <ipython-input-8-da600f9047ad> in <module> 60 try: ---> 61 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 62 try: ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in click(self) 79 """Clicks the element.""" ---> 80 self._execute(Command.CLICK_ELEMENT) 81 ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in _execute(self, command, params) 632 params['id'] = self._id --> 633 return self._parent.execute(command, params) 634 ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params) 320 if response: --> 321 self.error_handler.check_response(response) 322 response['value'] = self._unwrap_value( ~\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response) 241 raise exception_class(message, screen, stacktrace, alert_text) --> 242 raise exception_class(message, screen, stacktrace) 243 ElementClickInterceptedException: Message: element click intercepted: Element <a class=" _65Bje coreSpriteRightPaginationArrow" tabindex="0">...</a> is not clickable at point (460, 264). Other element would receive the click: <div class="RnEpo Yx5HN " role="presentation">...</div> (Session info: chrome=92.0.4515.131) During handling of the above exception, another exception occurred: ElementClickInterceptedException Traceback (most recent call last) <ipython-input-8-da600f9047ad> in <module> 78 79 except WebDriverException: ---> 80 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 81 print(now_time()+'次の投稿へ移動しました') 82 time.sleep(random.randint(3, 5)) ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in click(self) 78 def click(self): 79 """Clicks the element.""" ---> 80 self._execute(Command.CLICK_ELEMENT) 81 82 def submit(self): ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py in _execute(self, command, params) 631 params = {} 632 params['id'] = self._id --> 633 return self._parent.execute(command, params) 634 635 def find_element(self, by=By.ID, value=None): ~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params) 319 response = self.command_executor.execute(driver_command, params) 320 if response: --> 321 self.error_handler.check_response(response) 322 response['value'] = self._unwrap_value( 323 response.get('value', None)) ~\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response) 240 alert_text = value['alert'].get('text') 241 raise exception_class(message, screen, stacktrace, alert_text) --> 242 raise exception_class(message, screen, stacktrace) 243 244 def _value_or_default(self, obj, key, default): ElementClickInterceptedException: Message: element click intercepted: Element <a class=" _65Bje coreSpriteRightPaginationArrow" tabindex="0">...</a> is not clickable at point (460, 264). Other element would receive the click: <div class="RnEpo Yx5HN " role="presentation">...</div> (Session info: chrome=92.0.4515.131) ​ 0 12 Python 3 | Idle Saving completed お客様用.ipynb

該当のソースコード

Python

1try: 2 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 3 try: 4 print(now_time()+'次の投稿へ移動しました') 5 time.sleep(random.randint(3, 5)) 6 7 except ElementClickInterceptedException: 8 driver.find_elements_by_xpath('/html/body/div[6]/div/div/div/div[2]/div/div[2]/div').click() 9 wb=openpyxl.load_workbook('レポート.xlsx') 10 sheet = wb.active 11 sheet.cell(row=number_of_trials,column=1).value =pyperclip.paste() 12 wb.save('レポート.xlsx') 13 print('投稿urlを入力しました') 14 time.sleep(random.randint(3, 5)) 15 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 16 print(now_time()+'次の投稿へ移動しました') 17 time.sleep(random.randint(3, 5)) 18

試したこと

try,exceptで試してみましたが、なぜエラーが出るのか分かりませんでした。

補足情報(FW/ツールのバージョンなど)

windows10
Anaconda

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

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

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

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

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

guest

回答1

0

なぜエラーが出るのか

エラーメッセージにも記載がある通り

During handling of the above exception, another exception occurred:
(Google翻訳)上記の例外の処理中に、別の例外が発生しました

exceptの処理中にまた例外が発生してしまってるようです。
exceptの中に記述している処理をtryの中で出来るように
うまくコードを書くしかありませんね

投稿2021/08/10 13:36

odataiki

総合スコア938

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

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

Ju.-.

2021/08/10 16:32

コメントありがとうございます。 押せない状況では、二度目の「リンクをコピーする」ボタンが画面内に現れた場合のみ、ifで driver.find_elements_by_xpath('/html/body/div[6]/div/div/div/div[2]/div/div[2]/div').click() を行うようなコードを組みたいのですが、画面内に指定したボタンが存在するか確認する方法はありますか。もしあればご教授ください。お願いいたします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問