How to bring selenium browser to the front?

后端 未结 6 668
旧时难觅i
旧时难觅i 2021-02-08 06:24

if the browser window is in bg, then this line doesn\'t work.

from selenium import webdriver

from selenium.webdriver.common.keys import Keys
from selenium.webd         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 07:25

    This worked for me to bring the browser window to the foreground. I tested using chromedriver on Selenium 3.6.0 on Python 3.

    from selenium import webdriver
    
    driver = webdriver.Chrome()
    
    driver.switch_to.window(driver.current_window_handle)
    

    Related answer in Java - https://sqa.stackexchange.com/questions/16428/how-can-i-bring-chrome-browser-to-focus-when-running-a-selenium-test-using-chrom

提交回复
热议问题