Google chrome closes after adding the excel code but works without the excel code

Question:

I’m pretty new to Python and automation. I’m trying to automate logging in to a web page and add data which I’ve extracted from excel to a text box on the web page.

Opening the web pages works fine without adding the piece of code below.

import xlwings as xw

wb = xw.Book('myExcel.xlsx')
alertNumber = wb.app.selection

Before adding the above code chrome opens and goes to every URL and at the final page it stays open untill i click on close, but after adding the above piece of code the chrome closes after executing everyline.

Can someone explain what is missing as Im pretty new to coding.

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import xlwings as xw

wb = xw.Book('myExcel.xlsx')
alertNumber = wb.app.selection

uname = "[email protected]"
pword = "Th!s!smydummypa$$w0rd"

supportPortal = "https://url1.com"
openCase = "https://url2.com"
Path = "c:/chromedriver.exe"

driver = webdriver.Chrome(Path)

driver.get(supportPortal)
driver.find_element(By.NAME, "email").send_keys(uname)
driver.find_element(By.ID, "remember-cb").click()
driver.find_element(By.CSS_SELECTOR, ".submit-btn").click()
print("Username added")

time.sleep(2)

driver.find_element(By.ID, "password-sign-in").send_keys(pword)
driver.find_element(By.CSS_SELECTOR, ".submit-btn").click()
print("Password added")

print("Starting to wait")
time.sleep(20)
print("Wait is over")

driver.get(openCase)
driver.find_element(By.NAME, "alert_number").send_keys(alertNumber)
Asked By: lakpura.manul

||

Answers:

Thanks for the support, guys. I think I found the answer. webdriver closes the chrome session as soon as it finishes executing the code. Therefore, I added a

time.sleep(30)

to keep the chrome open until I get sufficeint time to do the changes.

Answered By: lakpura.manul