Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of pop-up window when python selenium is running

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to solve the pop-up window problem when python selenium is running". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the pop-up window problem when python selenium is running.

Remove python window

The project initially uses C++ 's process to call up python and execute the script, but later found that a python window will pop up.

The command used is

Python.exe ie.py

The effect is as follows

The page opens but a python window appears.

Solution

Use pythonw.exe instead.

In the same directory of the python.exe file, there is also an executable file called pythonw.exe, the difference between it and pyhon.exe is that pythonw.exe is a windowless python executable program, after running the script will be run in the background, there will be no window, there will be no output.

Remove driver window

After switching to the pythonw.exe window, it is found that the python window does not pop up, but when you are lucky with chrome and ie, the corresponding driver window will pop up.

The effect is as follows:

Solution

Through the search found that there have been bloggers through the implementation of their own classes so that the window no longer pop-up, learn from his ideas, because the project can directly provide python environment, so I chose to directly modify the source code implementation.

The details are as follows:

Modify the selenium/webdriver/common/service.py.

Add a few lines of code at the beginning of line 60 of service.py to modify the startup parameters

Si = subprocess.STARTUPINFO () si.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOWsi.wShowWindow = subprocess.SW_HIDE

In this way, if you modify it and run it, there will be no pop-up windows.

At this point, I believe that everyone on the "python selenium runtime pop-up window problem how to solve" have a deeper understanding, might as well to practical operation it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 219

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report