Objective
Sometimes the element has been found, the operation is not error, click on the page did not respond. This problem encountered, is more headache, because there is no error, but the click event is invalid.
This article uses 2 kinds of methods to solve this strange click event failure problem
First, the problems encountered
1. In the practice of Baidu's Search Settings button, click the Save Settings button, alert Pop popup (the code did not error, just get alert failure), I believe it is not only I have encountered.
Second, click on the parent element
1. This problem should be caused by the previous operation of the Select after the Sequela (because I commented out select that paragraph can be clicked successfully)
2. First solution, click on its parent element once, then click on this element
3. The implementation code is as follows
Third, JS Direct click
1. Encounter this strange problem, it is time to make a trick: JS Dafa
2. Execute the Click event directly with JS
Iv. Reference Code
# Coding:utf-8
From selenium import Webdriver
From Selenium.webdriver.common.action_chains import Actionchains
From Selenium.webdriver.support.select Import Select
Import time
Driver = Webdriver. Firefox ()
url = "Https://www.baidu.com"
Driver.get (URL)
Time.sleep (3)
Mouse = driver.find_element ("link text", "Settings")
Actionchains (Driver). Move_to_element (mouse). Perform ()
Time.sleep (3)
Driver.find_element ("link text", "Search Settings"). Click ()
Time.sleep (3)
s = driver.find_element ("id", "NR")
Select (s). Select_by_visible_text ("Show 50 per page")
# method One: First point the parent element communication QQ Group: 232607095
# driver.find_element ("id", "Gxszbutton"). Click ()
# driver.find_element ("Class name", "Prefpanelgo"). Click ()
# method Two: Use JS directly to click on the QQ group: 232607095
JS = ' Document.getelementsbyclassname ("Prefpanelgo") [0].click (); '
Driver.execute_script (JS)
Selenium2+python Automation 46-js Solve the click Failure problem