Selenium2+python Automation 46-js Solve the click Failure problem

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.