前提・実現したいこと
Python3でSeleniumを利用しています。
javascript:void(0)で設定しているimgボタンをクリックし、ポップアップを表示させたい。
実装されているHTML(クリックしたい個所)
<a href="javascript:void(0)"><img src="https://hoge/images/btn/cart.gif?magic=**********" class="btn" id="to_cart" /></a>
試したこと
1 <a href="javascript:void(0)"> のXPathを取得しクリックしようとする。
driver.find_element_by_xpath('//*[@id="centerCol"]/div[1]/div[4]/div[2]/a[2]').click()
2 <img src="https://hoge/images/btn/cart.gif?magic=**********" class="btn" id="to_cart" /> のXPathを取得しクリックしようとする。
driver.find_element_by_xpath('//*[@id="to_cart"]').click()
3 id="to_cart" のidを指定しクリックしようとする。
driver.find_element_by_id(to_cart).click()
発生している問題・エラーメッセージ
【 1 の場合のエラー】
Traceback (most recent call last): File "C:\Users\test\Desktop\Python\Selenium\test.py", line 61, in <module> driver.find_element_by_xpath('//*[@id="centerCol"]/div[1]/div[4]/div[2]/a[2]').click() File "C:\python\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\python\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params) File "C:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: element has zero size (Session info: chrome=84.0.4147.125)
【 2 と 3 の場合のエラー】
エラーの表示は無し。 ブラウザ上でも、何も起こらない。(ポップアップも表示されない)
補足情報(インポート、設定情報)
import os, pyodbc, datetime, shutil, time, chromedriver_binary import pandas as pd from selenium import webdriver options = webdriver.ChromeOptions() options.add_experimental_option('prefs', { 'download.default_directory': c_dir, 'download.prompt_for_download': False, 'download.directory_upgrade': True, 'safebrowsing.enabled': True }) options.add_argument('--ignore-certificate-errors') options.add_argument('--disable-extensions') options.add_argument('--disable-print-preview') driver = webdriver.Chrome(options=options)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。