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

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

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

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

selenium

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

Q&A

0回答

1619閲覧

python seleniumでボタンはクリック出来るが次の画面に切り替わらない。対処方法を教えてください。初心者です。

Ju.-.

総合スコア0

Python

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

selenium

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

0グッド

0クリップ

投稿2021/08/19 06:15

python seleniumでボタンはクリック出来るが次の画面に切り替わらない。対処方法を教えてください。初心者です。

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

1.「リンクをコピーする」→「次の投稿へ移動」
こちらはうまくいく

2.「リンクをコピーする」→「リンクをコピーする」→「次の投稿へ移動」ここでエラー

2度目の「リンクをコピーする」ボタンが画面上に出現した場合、ボタンはクリック出来るのですが、
なぜか次の画面に切り替わらいので、次に押したいボタンが画面に出現しないのでここでエラーが出ます。
エラーメッセージを見ると、次の投稿へいくところでエラーが出ているので、リンクをコピーするボタンはクリック出来ていると思います。クリック出来ているのに、手動でボタンを押したときのように作動しない原因を教えてください。またどのように書き換えるとうまく作動するかご教授ください。

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

ElementClickInterceptedException Traceback (most recent call last) <ipython-input-10-3f00594139ac> in <module> 80 try: ---> 81 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 82 print(now_time()+'次の投稿へ移動しました') ~\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-10-3f00594139ac> in <module> 84 85 except WebDriverException: ---> 86 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 87 print(now_time()+'次の投稿へ移動しました') 88 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)

該当のソースコード

Python

1#ここまででログイン、検索済み(長いので割愛) 2for i in range(likedMax-1): 3 try: 4 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 5 print(now_time()+'次の投稿へ移動しました') 6 time.sleep(random.randint(3, 5)) 7 8 except WebDriverException: 9 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 10 print(now_time()+'次の投稿へ移動しました') 11 time.sleep(random.randint(3, 5)) 12 13 except IndexError: 14 driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() 15 print(now_time()+'次の投稿へ移動しました') 16 time.sleep(random.randint(3, 5)) 17 18 19 20 try: 21 if check_Like(): 22 driver.find_element_by_class_name('fr66n').click() 23 print(now_time()+f'投稿をいいね{number_of_trials}回目') 24 time.sleep(random.randint(4, 6)) 25 #・・・ボタンを押す 26 driver.find_elements_by_xpath('//div[@class="QBdPU "]')[0].click() 27 time.sleep(2) 28 #リンクをコピーボタンを押す 29 driver.find_elements_by_xpath('//button[@class="aOOlW HoLwm "]')[2].click() 30 time.sleep(2) 31 322度目の「リンクをコピー」ボタンが画面上にあるか確認(2パターンあることを確認済み) 33 link1=driver.find_elements_by_xpath('/html/body/div[6]/div/div/div/div[2]/div/div[2]/div') 34 link2=driver.find_elements_by_xpath('/html/body/div[7]/div/div/div/div[2]/div/div[2]/div') 35 if len(link2)>0: 36 driver.find_element_by_xpath('/html/body/div[6]/div/div/div/div[2]/div/div[2]').click 37 print('2度目クリックしました') 38 39 40 elif len(link1)>0: 41 driver.find_element_by_xpath('/html/body/div[6]/div/div/div/div[2]/div/div[2]').click 42 print('2度目クリックしました') 43 44 45### 試したこと 46 47<div class="-qQT3" aria-disabled="false" role="button" tabindex="0"><div aria-labelledby="f6bbf9d157a9c f43b3b9a20ebec f3627c7e94e09c4" class=" Igw0E rBNOH eGOV_ ybXk5 _4EzTm XfCBB HVWg4 "><div class=" Igw0E IwRSH eGOV_ _4EzTm yC0tu "><div class="_NyRp"><span aria-label="リンクをコピー" class="glyphsSpriteLink__outline__24__grey_9 u-__7"></span></div></div><div class=" Igw0E IwRSH YBx95 vwCYk "><div class=" Igw0E IwRSH eGOV_ _4EzTm " id="f6bbf9d157a9c"><div class="_7UhW9 xLCgt MMzan KV-D4 fDxYl "><div class="_7UhW9 xLCgt qyrsm uL8Hv ">リンクをコピー</div></div></div></div></div></div> 48 49検証で見たときに、このように表示されるボタンをfullxpathで取得してクリックしています。 50 51 52 53### 補足情報(FW/ツールのバージョンなど) 54Windows10,python

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問