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.
JavaScript
x
5
1
import xlwings as xw
2
3
wb = xw.Book('myExcel.xlsx')
4
alertNumber = wb.app.selection
5
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.
JavaScript
1
36
36
1
from selenium import webdriver
2
from selenium.webdriver.common.by import By
3
import time
4
import xlwings as xw
5
6
wb = xw.Book('myExcel.xlsx')
7
alertNumber = wb.app.selection
8
9
uname = "dummy@example.com"
10
pword = "Th!s!smydummypa$$w0rd"
11
12
supportPortal = "https://url1.com"
13
openCase = "https://url2.com"
14
Path = "c:/chromedriver.exe"
15
16
driver = webdriver.Chrome(Path)
17
18
driver.get(supportPortal)
19
driver.find_element(By.NAME, "email").send_keys(uname)
20
driver.find_element(By.ID, "remember-cb").click()
21
driver.find_element(By.CSS_SELECTOR, ".submit-btn").click()
22
print("Username added")
23
24
time.sleep(2)
25
26
driver.find_element(By.ID, "password-sign-in").send_keys(pword)
27
driver.find_element(By.CSS_SELECTOR, ".submit-btn").click()
28
print("Password added")
29
30
print("Starting to wait")
31
time.sleep(20)
32
print("Wait is over")
33
34
driver.get(openCase)
35
driver.find_element(By.NAME, "alert_number").send_keys(alertNumber)
36
Advertisement
Answer
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
JavaScript
1
2
1
time.sleep(30)
2
to keep the chrome open until I get sufficeint time to do the changes.