How did i solve this problem? - First there is file with username:password format.
I made 2 other seperate text files called for example, username.txt and password.txt
Then i used regex to count words in a line, then using counted value to split the text where i wanted, since my text could be something like :
- user name:password
- us er name:password
- us_er.name:password
and so on. Since password never has any space between words, always last word is password.
import regex
lineinfo = open("allaccounts.txt", "r")
username = open("username.txt", "w")
password = open("password.txt", "w")
info = lineinfo.readline()
info2 = info.replace(':', ' ')
count = len(regex.findall(r'\S+', info2))
if count == 2:
info3 = info2.split()[0]
username.write(info3)
info4 = info2.split()[1]
password.write(info4)
if count == 3:
info3 = info2.split()[0]
info5 = info2.split()[1]
username.write(info3 + " " + info5)
info4 = info2.split()[2]
password.write(info4)
username.close() and password.close()
username = open("username.txt", "r")
password = open("password.txt", "r")
real_username = username.readline()
real_password = password.readline()
username.close()
password.close()
Yeah maybe this can be done in a much easier way but i started learining code like 4 days ago and this is what i could come up in the spot.
so the username will be rea_username and password real_password and i used them like
inputElement = driver.find_element_by_xpath('//*[@id="username"]')
inputElement.send_keys("real_username")
inputElement = driver.find_element_by_xpath('//*[@id="password"]')
inputElement.send_keys("real_password")