在使用 element.click() 時,會失效,雖然晝面看的到button, 但似乎在很邊邊,selenium 無法按到 element, 並 raise error:
Message: element not interactable (Session info: chrome=1xx.0.5359.124) Stacktrace: ....
解法:
from selenium.webdriver.common.action_chains import ActionChains builder = ActionChains(driver) builder.move_to_element(elm_Men_Menu).click(elm_FastTrack_Menu).perform()
或替代解法:
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()
但實際操作,還是一樣有錯誤訊息:
element not interactable: [object HTMLButtonElement] has no size and location
資料來源:
https://stackoverflow.com/questions/71238823/button-element-not-interactable-selenium
結論:無解,只好改用javascript 來做替代。
driver.execute_script("arguments[0].click();", el_btn)