selenium+python automation 95-pop-up box cannot be located alive or dead

foreword

After some friends learn selenium's alert, they will use alert regardless of the pop-up box. This will not work. When you see the pop-up box, you must first determine whether it is an alert or not. If it is not, it will definitely not work.

  • Some pop-up boxes are div layers, which are the same as the usual positioning methods

  • Some pop-up boxes are nested iframe layers, this kind of switching iframe is fine

  • Some pop-up boxes are rather pitted and are embedded windows, which is what this article is about.

Encounter problems

1. Recently, a small partner encountered the positioning of a pop-up box, as shown in the figure below, which seems to be an ordinary pop-up box

2. Encountered this problem and tried the following:

  • First of all, this is definitely not an alert, so you can't use alert to locate
  • Then see if there is an iframe, after viewing the element, I find that there is no iframe
  • The sleep time is added in front and it can't be solved

Solve the problem

1. Get all the windows by printing, and find that there are actually two handles printed, that is to say, this looks like a window on the surface, but actually another window is embedded.

# 作者:上海悠悠

# 打印所有的handle
all_handles = driver.window_handles
print(all_handles)

# 切换到新的handle上
driver.switch_to.window(all_handles[1])

2. Find the cause of the problem, the next step is simple, first switch to a new window, and then use the usual positioning method.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325341410&siteId=291194637