Click to report an error
When using selenium, click events are triggered, and the following exceptions are often reported:
Element is not clickable at point
Causes and Solutions
There are four reasons
1. Not loaded
Wait for the element to be loaded before proceeding
you can use the python library
import time
time.sleep(3)
But it’s better to use selenium’s own webdriverwait
from selenium.webdriver.support.ui import WebDriverWait
WebDriverWait(driver, 10).until(EC.title_contains("element"))
For the specific usage of webdriverwait, please click the reference document
2. In iframe
If the element is in the iframe, you can’t find it in the window, and you can’t click it. So, switch to iframe to find the element
driver.switch_to_frame("frameName") # Switching by frame name
driver.switch_to_frame("frameName.0.child") # child frame
driver.switch_to_default_content() # return
For other related switching, please click the reference document
3. Not in the window, need to pull the scroll bar
The list page of many websites does not return all the contents immediately, but is displayed according to the view. Therefore, we need to drag the scroll bar to display the content to be obtained in the window
page = driver.find_element_by_partial_link_text(u'next page')
driver.execute_script("arguments[0].scrollIntoView(false);", page)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, u'next page'))).click()
About the contents of the drop-down scroll bar, please refer to the blog
4. The element to be clicked is covered
You can use the event chain to solve
problems, such as drop-down menus, which can be displayed through the hover, and then you can click
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
For details of the event chain, please click document