การทำ webdriver บน Python GUI (Tkinter)

Software testing ความรู้ สำหรับ Tester ผู้ทดสอบ เป็นส่วนสำคัญในการ test โปรแกรม การ ทดสอบโปรแกรมมีความรู้แนะนำไว้ในหมวดนี้

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Jom07
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 514
ลงทะเบียนเมื่อ: 08/01/2018 9:56 am

การทำ webdriver บน Python GUI (Tkinter)

โพสต์ที่ยังไม่ได้อ่าน โดย Jom07 »

การทำ webdriver บน Python GUI (Tkinter)

โค้ด: เลือกทั้งหมด

from tkinter import *
from tkinter import messagebox as ms
from selenium import webdriver
import sqlite3
เริ่มแรกเป็นการ import tkinter,selenium webdriver เพื่อสร้างหน้าต่างกับ เรียก wabdriver ขึ้นมา

โค้ด: เลือกทั้งหมด

        with sqlite3.connect('quit.db') as db:
            c = db.cursor()
        find_user = ('SELECT * FROM user WHERE username = ? and password = ?')
        c.execute(find_user,[(self.username.get()),(self.password.get())])
        result = c.fetchall()
        if result:
            self.logf.pack_forget()
            self.head['text'] = self.username.get() + '\n Loged In'
            self.head['pady'] = 150
        else:
            chromedriver = 'D:\\chromedriver_win32\\chromedriver.exe'
            brower = webdriver.Chrome()
            brower.get('------------------------------------------------------------'')
เป็นการเรียก webdriver มาใช้งาน โดยโหลด webdriver แล้วกำหนดที่อยู่ ในที่นี้ จะเอาใว้ไดร์ D

โค้ด: เลือกทั้งหมด

def widgets(self):
        self.head = Label(self.master,text = 'LOGIN',font = ('',25),pady = 10)
        self.head.pack()
        self.logf = Frame(self.master,padx =10,pady = 10)
        Label(self.logf,text = 'Host Name : ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.hostname,bd = 5,font = ('',15)).grid(row=0,column=1)
        Label(self.logf,text = '-------------',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15)).grid(row=1,column=1)
        Label(self.logf,text = 'Username  : ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.username,bd = 5,font = ('',15)).grid(row=2,column=1)
        Label(self.logf,text = 'Password  : ',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15),show = '*').grid(row=3,column=1)
        Label(self.logf,text = '-------------',font = ('',20),pady=5,padx=5).grid(sticky = W)
        Entry(self.logf,textvariable = self.password,bd = 5,font = ('',15)).grid(row=4,column=1)
        Button(self.logf,text = ' RUN ',bd = 3 ,font = ('',14),padx=5,pady=5,command=self.login).grid(row=7,column=1)
        Button(self.logf,text = ' --- ',bd = 3 ,font = ('',14),padx=5,pady=5,command=self.login).grid(row=7,column=2)
        self.logf.pack()
การสร้าง ช่องใส่ข้อมูล และปุ่มคลิก Button ขึ้นมาให้งาน

ผลรัน
รูปภาพ

จะขึ้นหน้าต่างนี้มาเมื่อกดปุ่มรันจะขึ้น webdriver ที่เรากำหนดใว้
แก้ไขล่าสุดโดย mindphp เมื่อ 15/02/2018 7:04 pm, แก้ไขไปแล้ว 1 ครั้ง.
เหตุผล: แก้ไข โพส แชร์ ไม่ต้องตามรูปแบบ
รูปภาพ
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 43