leom4life sw
leom4life sw

Reputation: 19

running selenium without chromedriver popping out

is there a way i can run selenium without it popping out?

i am using windows and using python 3.8.

i have tried using the "ghostdriver" but it didn't work for some reason.

here is what im using selenium for:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from getpass import getpass
import time
import os
import password_for_github

#C:\Users\no\Downloads\chromedriver_win\chromedriver.exe chrome driver
rep_name = str(input("rep name: "))
descrepition = str(input("rep description: "))
username = '[email protected]'
password = password_for_github.password_HELLO
password1 = password_for_github.password_HELLO

if password == password1:
    driver = webdriver.Chrome('C:\\Users\Anas\Downloads\chromedriver_win\chromedriver.exe')
    driver.get('https://github.com/login')
    time.sleep(1)

    username_login = driver.find_element_by_id("login_field")
    username_login.send_keys(username)
    time.sleep(0.001)

    password_login = driver.find_element_by_id("password")
    password_login.send_keys(password)
    time.sleep(0.001)

    login_button = driver.find_element_by_xpath('//*[@id="login"]/form/div[4]/input[9]')
    login_button.submit()
    time.sleep(0.0001)
    
    driver.get("https://github.com/new")

    new_projectname = driver.find_element_by_id("repository_name")
    new_projectname.send_keys(str(rep_name))

    project_description = driver.find_element_by_xpath('//*[@id="repository_description"]')
    project_description.send_keys(descrepition)

    create_rep = driver.find_element_by_xpath('//*[@id="new_repository"]/div[4]/button')
    create_rep.submit()
    driver.quit()
    
elif password != password1:
    print("wrong password try again (restart) ")

Upvotes: 0

Views: 118

Answers (1)

Krzysztof
Krzysztof

Reputation: 147

I think you are looking for headless Chrome

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('headless')
path = 'C:\\Users\Anas\Downloads\chromedriver_win\chromedriver.exe'
driver = webdriver.Chrome(path, options=options)

Upvotes: 2

Related Questions