โดย rangsan » 25/05/2018 11:32 am
ตอนนี้ต้องการให้ Python GUI( Tkinter ) เก็บ Path ที่ได้จากการ Browse เพื่อเก็บค่าของ Path นั้นส่งไปที่ไฟล์ที่ใช้ Run Selenium ครับ และตอนนี้ผมได้สร้างหน้า Forms ของการ Browse Path มาแล้วครับ แต่เมื่อ Browse Path มาแล้วต้องการให้ มันส่งค่าของ Path ไปที่ File ที่ใช่ในการ Run Selenium Webdriver ครับ
ตัวอย่างหน้า Forms
- Form_GUI.png (14.6 KiB) Viewed 1672 times
และเมื่อผมทำการเลือก Path ที่ใช้ในการเปิด Browser ของ Firefox จะเป็นตัว geckodriver ครับ
- Path_GUI.png (83.21 KiB) Viewed 1672 times
เมื่อกด Open ก็จะได้ Path มาแบบนี้ครับ
- Ex_path.png (19.97 KiB) Viewed 1672 times
จากนั้นกด Run แล้วเกิด Error ครับ
- Error.png (53.1 KiB) Viewed 1672 times
จะเห็นว่าไฟล์ที่เกิด Error คือ selenium_autorat บรรทัดที่ 21 ซึ่งเป็นโค้ดที่ใช้เปิด Path ของ Browser Firefox ครับ คือตัว geckodriver
โค้ด: เลือกทั้งหมด
def setUp(self):
self.driver = webdriver.Firefox(executable_path=firefox)
ภาพตัวอย่างประกอบ
- Selection_116.png (15.15 KiB) Viewed 1672 times
โดยตัวแปร firefox นั้นผมได้สั่งให้เก็บค่าจากไฟล์ที่ใช้ในการสร้าง Python GUI( Tkinter )
โค้ด: เลือกทั้งหมด
def __init__(self,master):
self.master = master
# self.hostname = StringVar()
self.pathwebdriver = StringVar()
self.widgets()
def login(self):
# link = self.hostname.get()
# __builtin__.base_url = link
__builtin__.firefox = self.pathwebdriver.get()
suite = unittest.TestLoader().loadTestsFromModule(selenium_autorat)
unittest.TextTestRunner(verbosity=2).run(suite)
def widgets(self):
self.head = Label(self.master,text = 'SELECT PATH',font = ('',25),pady = 10)
self.head.pack()
self.logf = Frame(self.master,padx =10,pady = 10)
Label(self.logf,text = 'Path Webdriver ',font = ('',20),pady=5,padx=5 ).grid(row=0)
Entry(self.logf,textvariable = self.pathwebdriver,bd = 5,font = ('',15)).grid(row=0,column=1)
Button(self.logf,text = ' RUN ',bd = 3 ,font = ('',12),padx=5,pady=5, command=self.login).grid(row=1,column=1)
Button(self.logf,text = ' Browse ' ,bd = 3 ,font = ('',10),padx=5,pady=5, command=self.selection).grid(row=0,column=2)
Button(self.logf,text = ' Close ',bd = 3 ,font = ('',12),padx=5,pady=5, command=root.destroy).grid(row=1,column=2)
self.logf.pack()
ภาพตัวอย่างประกอบ
- Selection_117.png (86.49 KiB) Viewed 1672 times
อยากทราบว่าเป็นเพราะอะไรครับ
ตอนนี้ต้องการให้ Python GUI( Tkinter ) เก็บ Path ที่ได้จากการ Browse เพื่อเก็บค่าของ Path นั้นส่งไปที่ไฟล์ที่ใช้ Run Selenium ครับ และตอนนี้ผมได้สร้างหน้า Forms ของการ Browse Path มาแล้วครับ แต่เมื่อ Browse Path มาแล้วต้องการให้ มันส่งค่าของ Path ไปที่ File ที่ใช่ในการ Run Selenium Webdriver ครับ
ตัวอย่างหน้า Forms
[attachment=5]Form_GUI.png[/attachment]
และเมื่อผมทำการเลือก Path ที่ใช้ในการเปิด Browser ของ Firefox จะเป็นตัว geckodriver ครับ
[attachment=4]Path_GUI.png[/attachment]
เมื่อกด Open ก็จะได้ Path มาแบบนี้ครับ
[attachment=3]Ex_path.png[/attachment]
จากนั้นกด Run แล้วเกิด Error ครับ
[attachment=2]Error.png[/attachment]
จะเห็นว่าไฟล์ที่เกิด Error คือ selenium_autorat บรรทัดที่ 21 ซึ่งเป็นโค้ดที่ใช้เปิด Path ของ Browser Firefox ครับ คือตัว geckodriver
[code] def setUp(self):
self.driver = webdriver.Firefox(executable_path=firefox)[/code]
ภาพตัวอย่างประกอบ
[attachment=1]Selection_116.png[/attachment]
โดยตัวแปร firefox นั้นผมได้สั่งให้เก็บค่าจากไฟล์ที่ใช้ในการสร้าง Python GUI( Tkinter )
[code] def __init__(self,master):
self.master = master
# self.hostname = StringVar()
self.pathwebdriver = StringVar()
self.widgets()
def login(self):
# link = self.hostname.get()
# __builtin__.base_url = link
__builtin__.firefox = self.pathwebdriver.get()
suite = unittest.TestLoader().loadTestsFromModule(selenium_autorat)
unittest.TextTestRunner(verbosity=2).run(suite)
def widgets(self):
self.head = Label(self.master,text = 'SELECT PATH',font = ('',25),pady = 10)
self.head.pack()
self.logf = Frame(self.master,padx =10,pady = 10)
Label(self.logf,text = 'Path Webdriver ',font = ('',20),pady=5,padx=5 ).grid(row=0)
Entry(self.logf,textvariable = self.pathwebdriver,bd = 5,font = ('',15)).grid(row=0,column=1)
Button(self.logf,text = ' RUN ',bd = 3 ,font = ('',12),padx=5,pady=5, command=self.login).grid(row=1,column=1)
Button(self.logf,text = ' Browse ' ,bd = 3 ,font = ('',10),padx=5,pady=5, command=self.selection).grid(row=0,column=2)
Button(self.logf,text = ' Close ',bd = 3 ,font = ('',12),padx=5,pady=5, command=root.destroy).grid(row=1,column=2)
self.logf.pack()[/code]
ภาพตัวอย่างประกอบ
[attachment=0]Selection_117.png[/attachment]
อยากทราบว่าเป็นเพราะอะไรครับ