im using selenium and after i run the code a new chrome window pop up the close by it self

Viewed 24

here is the code

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

brow=webdriver.Chrome(ChromeDriverManager().install())

brow.get("https://wuzzuf.net/search/jobs/?q=paython&a=hpb")
2 Answers

So essentially, this is normal behavior--when you reach the end of your script the browser will close. Try the following and observe that the browser stays open as long as you tell it to.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

option = webdriver.ChromeOptions()
option.add_argument("start-maximized")
option.add_experimental_option("detach",True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)


driver.get('https://wuzzuf.net/search/jobs/?q=paython&a=hpb')
time.sleep(5)
driver.find_element(By.CSS_SELECTOR, 'input[value="paython"]').send_keys("some stuff")
time.sleep(5)

Also, I'm not sure what syntax you used for detach; the following works for me:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

option = webdriver.ChromeOptions()
option.add_argument("start-maximized")
option.add_experimental_option("detach",True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)


driver.get('https://wuzzuf.net/search/jobs/?q=paython&a=hpb')

it actually worked by this way

from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options=webdriver.ChromeOptions()

options.add_experimental_option("detach",True)
driver=webdriver.Chrome(options=options,service=Service(ChromeDriverManager().install()))

driver.get("https://wuzzuf.net/search/jobs/?a=hpb%7Cspbg&q=python")
driver.maximize_window()
Related