Python Selenium Another way to get out of the popup box

Source: Internet
Author: User

We all know that pop-up boxes can be roughly divided into three types: 1. Warning message box (alert), 2. Confirmation message box (confirm), 3. Prompt message dialog (prompt)

The selenium provides the Switch_to_alert () method to locate:

    • Switch_to_alert () #定位弹出对话
    • Text () #获取对话框文本值
    • Accept () #相当于点击 "Confirm"
    • Dismiss () #相当于点击 "Cancel"
    • Send_keys () # Input value

The above is the general pop-up box processing method, but I encountered a DIV simulation in the Project window, using the above method can not get this popup box:

For example:

After the usual methods have been tried, I think of two solutions: 1. Return to the top of the current page and get the page value; 2. Locate the confirmation button to determine the popup box.

In this case, I chose the 2nd method:

1     Try:2Driver.find_element_by_xpath ("/html/body/div[10]/div/div[2]/button"). Click ()3     except:4         Print('number of data copied to:')5     Else:6         Print('read timeout, refresh and try again! ')

Sometimes the other way of thinking ... Things can be solved.

Python Selenium Another way to get out of the popup box

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.