How to bring selenium browser to the front?

后端 未结 6 744
旧时难觅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:13

    Out of box, selenium does not expose driver process id or Browser hwnd but it is possible. Below is the logic to get hwnd

    • When driver is initialized, get the url for hub and extract the port number
    • From port number, find the process id which is using this port for listening, ie. PID of driver
    • After navigation, from all instances of iexplore find the parent PID matches the pid of driver, i.e browser pid.
    • Get the Hwnd of browser pid once browser hwnd is found , you can use win32 api to bring selenium to foreground.

    its not possible to post full code here, the full working solution (C#) to bring browser in front is on my blog

    http://www.pixytech.com/rajnish/2016/09/selenium-webdriver-get-browser-hwnd/

提交回复
热议问题