How can I loop through each text in tkinter entry box and use selenium to fill website forms with the data in my entry widgets? I have managed to do so but it works only if I have one text in each entry widget. I want to add for example more order numbers and automate the form filling. Here is the code and the GUI that I made:
Code is below:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import os
from selenium.webdriver import ChromeOptions
from selenium.webdriver.support import expected_conditions as EC, wait
from selenium.webdriver.support.ui import Select
import tkinter as tk
from tkinter.scrolledtext import ScrolledText
root=tk.Tk()
HEIGHT=300
WIDTH=500
POkeyword_list=StringVar()
SW1keyword_list=StringVar()
SW2keyword_list=StringVar()
def chromeO():
os.startfile(r'C:Users\me\Desktop\SeleniumChrome')
options = ChromeOptions()
options.debugger_address = "ip:port"
bot=webdriver.Chrome(chrome_options=options)
url = "link"
PO=POentry.get()
bot.get(url + PO)
time.sleep(2)
editheader = bot.find_element_by_name("editHeaderButton").click()
SW1=str((StartSW_entry.get()))
SW2=str((EndSW_entry.get()))
time.sleep(2)
startswbox = bot.find_element_by_name("earliestShipDate").clear()
startswbox = bot.find_element_by_name("earliestShipDate").send_keys(SW1)
endswbox= bot.find_element_by_name("latestShipDate").clear()
endswbox = bot.find_element_by_name("latestShipDate").send_keys(SW2)
time.sleep(1)
savebtn=bot.find_element_by_name("saveButton__").click()
popup=bot.switch_to_alert().accept()
#Create label, entry box and click button
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
root.title('Ship Window Butler') #Program Title
root.iconbitmap("C:/Users/me/Documents/Python Projects/WebTest/Butler1.ico") #Program icon
#Create background image
background_image=tk.PhotoImage(file='Code_presentation_background.png')
background_label = tk.Label(root, image=background_image)
background_label.place(relwidth=1, relheight=1)
#Create Order number
POlabel=tk.Label(root, text="Order number")
POlabel.place(relx=0.2,rely=0.2,anchor="n")
POentry = tk.Entry(root, bg="white",textvariable=POkeyword_list)
POentry.place(relx=0.2,rely=0.3,anchor="n")
#Create click button
Submitbutton=tk.Button(root, text="Click", command=lambda:chromeO())
Submitbutton.place(relx=0.5,rely=0.8, anchor="n")
#Create Action1 box
StartSW_label=Label(root, text="Action 1")
StartSW_label.place(relx=0.5, rely=0.2, anchor="n")
StartSW_entry=Entry(root, bg="white",textvariable=SW1keyword_list)
StartSW_entry.place(relx=0.5, rely=0.3, anchor="n")
#Create Action 2 box
EndSW_label=Label(root, text="Action 2")
EndSW_label.place(relx=0.8, rely=0.2, anchor="n")
EndSW_entry=Entry(root, bg="white",textvariable=SW2keyword_list)
EndSW_entry.place(relx=0.8, rely=0.3, anchor="n")
def test():
print((POkeyword_list.get()).split(" "))
print((SW1keyword_list.get()).split(" "))
print((SW2keyword_list.get()).split(" "))
button = Button(root, text="Ok", command=lambda:test())
button.pack()
root.mainloop()