0

我试图在按下按钮小部件时打开指定的 url,以便进一步使用 selenium 进行测试。

问题是我似乎无法从 tkinter 小部件获取 url 并将其与 webdriver 一起使用。

经过几次失败的尝试后,我开始向后工作,以查看驱动程序在正常输入driver.get('www.google.com')时是否会打开一个 url,但这似乎失败了。我搞砸了命令的调用方式吗?

这是一段代码(试图标记所有内容,如果您需要更多解释,请告诉我)

import tkinter as tk
from tkinter import *
import pyautogui
import requests
from time import sleep
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.opera.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.wait import WebDriverWait

#main window
main = tk.Tk()
main.geometry("300x550")
main.title("test")

#Background image
image2 = PhotoImage(file = "pew.png")
label1 = Label(main, image = image2)
label1.place(x=0,y=0)
main.configure(bg='black')

#First label
Label2 = Label(main, text='Enter URL:', bg='#26E600')
Label2.place(x=7,y=460)

#First entry box
Ent1 = Entry(main, textvariable='', bg='#ededed', show=None)
Ent1.place(x=75,y=460,width=210,height=22)

###### Having trouble pulling the URL from Ent1 and using it in the driver.get() function.
def rip():
    global Ent1
    driver = webdriver.Edge(r"PATH")
    sleep(0.5) #Sleep was inserted to see if driver.get was conflicting with the opening of the webdriver from path
    driver.get()   

#First Button
test = Button(main, text="test", bg='#26E600', show=None, command=rip)
test.place(x=7, y=500,width=100,height=22)

main.mainloop()
4

0 回答 0