如何自动使用Tkinter硒填充表格?

问题描述

如何在tkinter输入框中循环浏览每个文本,并使用selenium将输入小部件中的数据填充到网站表单中?我已经设法做到了,但是只有在每个输入小部件中只有一个文本的情况下,它才有效。例如,我想添加更多订单号并自动填写表格。这是我制作的代码和GUI:

enter image description here

代码如下:

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,anchor="n")
StartSW_entry=Entry(root,textvariable=SW1keyword_list)
StartSW_entry.place(relx=0.5,anchor="n")



#Create Action 2 box
EndSW_label=Label(root,text="Action 2")
EndSW_label.place(relx=0.8,anchor="n")
EndSW_entry=Entry(root,textvariable=SW2keyword_list)
EndSW_entry.place(relx=0.8,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()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...