I would like to manage python selenium login ID and password in a separate file.
When I looked it up on the Internet, I heard that I would use configparser and ini, so I tried it.
I put the config.ini file on my desktop and went to load it, but it didn't work.
It doesn't have to be a configparser and ini file method, but what I want to do is to take my ID and PW out of the code and manage it by the user through text files.
Is there something wrong with the ini file?
If you understand, please let me know.
MissingSectionHeaderError: File contains no section headers.
[user]
name —nnnnnnn
password —ppppppppp
from selenium import webdriver
import configparser
infile=configparser.ConfigParser()
infile.read (r'C:\Users\****\Desktop\config.ini', 'UTF-8')
driver = webdriver.Chrome("chromedriver.exe")
# driver = webdriver.Chrome()
driver.get('http://www.****.biz/login/index.html')
elem_username=driver.find_element_by_name('id')
elem_username.send_keys(inifile.get('user', 'name')))
elem_password=driver.find_element_by_name('passwd')
elem_password.send_keys(inifile.get('user', 'password')))
driver.find_element_by_class_name('alpha').click()
driver.execute_script('close_popup();')
Python 3.7.3
Windows 7
jupyter notebook
chromedriver
When editing the ini file in Notepad, it seems that the reason is that the BOM was attached.
Instead, creating a new file in Hidemaru solved the problem.
referenced sites:
"File contains no section headers.file:…" error and Trac project cannot be opened
This post is Posted as a community wiki based on @Tanichan's comment.
© 2024 OneMinuteCode. All rights reserved.