前提・実現したいこと
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

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/08/10 16:32