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