简体   繁体   English

如何将浏览器置于最前面并最大化使用 Selenium Python

[英]How to bring browser to front and maximize using Selenium Python

I am working on automating a section of data entry using a mixture of Selenium and Pyautogui.我正在使用 Selenium 和 Pyautogui 的混合物来自动化一部分数据输入。

I have the manual automated part down using the module Pyautogui but I need to bring the browser to the front so the mouse and keyboard can interact with the browser.我使用 Pyautogui 模块关闭了手动自动化部分,但我需要将浏览器置于最前面,以便鼠标和键盘可以与浏览器交互。

All the solutions I've tried maximizes the window but it stays in the background.我尝试过的所有解决方案都使 window 最大化,但它留在后台。

Try the below尝试以下

from selenium import webdriver

driver = webdriver.Chrome()

driver.switch_to.window(driver.current_window_handle)

To bring the browser to frontground and maximize using Selenium and Python you can use the following set of lines:要将浏览器带到前台并使用SeleniumPython最大化,您可以使用以下几行:

driver.execute_script("window.focus();")
driver.maximize_window()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM