Hello I’m new to python and jumped into trying to automate reading my work schedule for fun really and have run into a block…
I’ve written some code and it just won’t print in my main project but when taken out to test independently it runs just fine.
what am I doing wrong?
the with statement is what isn’t working, nothing gets printed to console, but again works on its own in a separate project and correctly prints.
(I took out the xpaths and stuff for safety)
JavaScript
x
33
33
1
from selenium import webdriver
2
from datetime import date
3
import sys
4
5
driver = webdriver.Chrome()
6
driver.get('')
7
userid = driver.find_element_by_xpath('')
8
password = driver.find_element_by_xpath('')
9
10
userid.send_keys('')
11
password.send_keys('')
12
13
loginbutton = driver.find_element_by_xpath('')
14
loginbutton.click()
15
16
schedule = driver.find_element_by_xpath('')
17
schedule.click()
18
19
date = date.today()
20
currentdate = date.strftime("%d")
21
22
23
wholeschedule = driver.find_element_by_xpath('').text
24
outF = open("schedule.txt", "w")
25
outF.write(wholeschedule)
26
27
with open('schedule.txt',"r") as file:
28
for line in file:
29
if ':' not in line and currentdate in line:
30
print('today is the: ' + currentdate)
31
print(next(file), end='')
32
break
33
Advertisement
Answer
You never closed outF
, so the data written to it likely never got physically written to the disk
. Insert outF.close()
after the with block.