Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用tkinter selenium自动填写表单?_Python_Selenium_Tkinter_Web Testing_Webautomation - Fatal编程技术网

Python 如何使用tkinter selenium自动填写表单?

Python 如何使用tkinter selenium自动填写表单?,python,selenium,tkinter,web-testing,webautomation,Python,Selenium,Tkinter,Web Testing,Webautomation,如何循环查看tkinter输入框中的每个文本,并使用selenium在输入窗口小部件中用数据填充网站表单?我已经设法做到了,但只有当我在每个条目小部件中有一个文本时,它才会起作用。例如,我想添加更多订单号并自动填写表单。以下是我制作的代码和GUI: 代码如下: from selenium import webdriver from selenium.webdriver.common.keys import Keys import time import os from selenium.web

如何循环查看tkinter输入框中的每个文本,并使用selenium在输入窗口小部件中用数据填充网站表单?我已经设法做到了,但只有当我在每个条目小部件中有一个文本时,它才会起作用。例如,我想添加更多订单号并自动填写表单。以下是我制作的代码和GUI:

代码如下:

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()

请说得更清楚些,问题是具体的。我编写的程序打开一个网页,并用文本框中写入的数据填充该网页中的表单。接下来需要的是在小部件中添加更多文本,并自动填充Web表单。Webdriver将从小部件中获取第一个项目,完成表单填写,然后循环到下一个项目。因此,每次填写文本框时,您都希望web驱动程序使用这些文本框中的文本填写表单?当然,在我按下单击按钮后,我发出了命令。该程序只在每个文本框中有一个字符串时工作,我希望它通过选择第一个字符串,上传,然后获取下一个字符串来工作。字符串用逗号分隔。请说得更清楚些,问题是具体的。我编写的程序打开一个网页,并用文本框中写入的数据填充该网页中的表单。接下来需要的是在小部件中添加更多文本,并自动填充Web表单。Webdriver将从小部件中获取第一个项目,完成表单填写,然后循环到下一个项目。因此,每次填写文本框时,您都希望web驱动程序使用这些文本框中的文本填写表单?当然,在我按下单击按钮后,我发出了命令。该程序只在每个文本框中有一个字符串时工作,我希望它通过选择第一个字符串,上传,然后获取下一个字符串来工作。字符串以逗号分隔。