Selenium multi-window, handle! what? Do you not understand these operations? (Python articles)


Multiple windows/handles

After the link of some pages is opened, a window will be reopened. In this case, if you want to operate on a new page, you have to switch windows first. The unique identifier of the obtained window is represented by a handle, so we only need to switch the handle, and we can operate flexibly on multiple pages.

1. Know multiple windows

2. Get the current window handle

1. Elements have attributes, and browser windows actually have attributes, but you can’t see them. The attributes of browser windows are identified by handles.

2. For human operation, you can recognize different windows and click to switch. But the script has no eyesight. It doesn't know which window you want to operate. At this time, it can only be judged by the handle.

3. Get the handle of the current page: driver.current_window_handle

Insert picture description here

3. Get all handles

1. Locate the job search button of Ganji.com and click

2. After clicking, get the current handle: window_handles

Note:

Obtaining multiple handles is a list type, so to switch to the corresponding handle, use the list method to operate

4. Switch handle

Note:

1. If you want to operate other windows, you must switch windows first

If the article is helpful to you, please reach out to make a fortune and give me a like. Thank you for your support. Your likes are my motivation for continuous updating.


Finally: benefits

In the technology industry, you must improve your technical skills and enrich your practical experience in automation projects. This will be very helpful for your career planning in the next few years and the depth of your testing technology.

In the interview season of Golden 9th and Silver 10th, job-hopping season, organizing interview questions has become my habit for many years! The following is my collection and sorting in recent years, the whole is organized around [software testing], the main content includes: python automation test exclusive video, Python automation details, a full set of interview questions and other knowledge content.

For software testing friends, it should be the most comprehensive and complete interview preparation warehouse. In order to better organize each module, I also refer to many high-quality blog posts and projects on the Internet, and strive not to miss every knowledge point. Friends relied on these contents to review, and got offers from big factories such as BATJ. This warehouse has also helped many software test learners, and I hope it can help you too!

May you and I meet and you will find something! Welcome to follow the WeChat public account: [Sad Spicy Article] Receive a 216-page software test engineer interview book for free. And the corresponding video learning tutorials are free to share!

Guess you like

Origin blog.csdn.net/weixin_50829653/article/details/112896884