Pythonのseleniumにてブラウザ操作をしています。
途中までは上手くいくのですが、あるボタンをクリックしようとしたときに
なぜか下記のエラーが出てしまいます。
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="forward_rblgi01_s01"]"}
該当部分のHTMLソースは下記です↓
HTML
<input type="image" name="forward_rblgi01_s01" src="/docs/0149/0/images/densi_syomeisyo_login_btn.png" onclick="return executeSubmitDomain(this.name);" alt="電子証明書ログイン">
実行しているコードは下記となります。
Python
from selenium import webdriver import chromedriver_binary from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException import unittest, time, re class AppDynamicsJob(unittest.TestCase): def setUp(self): # AppDynamics will automatically override this web driver # as documented in https://docs.appdynamics.com/display/PRO44/Write+Your+First+Script self.driver = webdriver.Chrome() self.driver.implicitly_wait(30) self.base_url = "https://www.google.com/" self.verificationErrors = [] self.accept_next_alert = True def test_app_dynamics_job(self): driver = self.driver driver.get("https://www.shizuokabank.co.jp/corporation/index.html") driver.find_element_by_xpath(u"//img[@alt='ログインはこちら']").click() # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_1 | ]] driver.find_element_by_name("forward_rblgi01_s01").click() driver.find_element_by_xpath("//input[@name='']").click() # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_2 | ]] driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_xpath("//button[@value='0']").click() driver.find_element_by_id("confirmBtn").click() driver.close() # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | win_ser_1 | ]] driver.find_element_by_id("loginBtn").click() def is_element_present(self, how, what): try: self.driver.find_element(by=how, value=what) except NoSuchElementException as e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True def close_alert_and_get_its_text(self): try: alert = self.driver.switch_to_alert() alert_text = alert.text if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert_text finally: self.accept_next_alert = True def tearDown(self): # To know more about the difference between verify and assert, # visit https://www.seleniumhq.org/docs/06_test_design_considerations.jsp#validating-results self.assertEqual([], self.verificationErrors) if __name__ == "__main__": unittest.main()
エラー箇所は上記コードの下記の部分です。
driver.find_element_by_name("forward_rblgi01_s01").click()
要素指定方法をxpathに変えても同じエラーが出てしまいます。
どのように変更すればうまくいくのか悩んでいます。
ご知見のおありになります方どうぞよろしくお願いいたします。
環境:Windows10
Python 3.7.3
まだ回答がついていません
会員登録して回答してみよう