Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

python - How to execute tests with selenium webdriver while browser is minimized

I try to run this program. it works fine with codes, however when I minimized the browser, error pop up. it seem that program is unable to find the button. is there anything that i can use to fix it. help

import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import os
import datetime
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox as msgbox

# Using Chrome to access web
driver = webdriver.Chrome()


master = Tk()
master.resizable(0, 0) #0 means false
genType = StringVar(master)       
options = ["1-Day Admission Only", "Audio Only"]
genType.set(options[0])


def optionChanged(var):
    if var == "1-Day Admission Only":
        met()
    elif var == "Audio Only":
        met()

genTypeMenu = OptionMenu(master, genType, *options, command=optionChanged)
        
def start():
    opt = genType.get()
          
    if opt == "1-Day Admission Only":


        
def met_one_day_admission():
    for i in range(int(qty.s.get())): 
        #do somethig here
        
b = Button(master, text="Start", width=20, command=start, fg="red")    
        
qty = entry_with_label("Quantity :", "100")


genTypeMenu.pack()
b.pack()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you initiate the Test Execution through Selenium, normally the Browser is initiated in maximized mode. Now, to execute your program/script, Selenium needs the focus on the Browser Client which renders the HTML DOM. When the Test Execution is In Progress if an user manually forcefully minimizes the browser, Selenium would loose the focus and an exception will be raised at any point of time which will halt the Test Execution.

You can find a detailed discussion in Selenium stops when browser is manually interrupted

Why does minimized browser give element not found error

WebDriver drives the browser directly using the browser’s built in support for automation. WebDriver attempts to model the user experience and actions as closely as possible and makes direct calls to the browser using each browser’s native support for automation. Modeling the user experience requires certain design, technology and support for interacting with elements. These interactions and the features they support depends on the browser you are using. In short, most likely Selenium won't work if the browser is minimized since a user cannot interact with the webpage while the browser window is minimized.

You can find a detailed analysis from @JimEvans in Selenium -Why does minimized browser give element not found error whereas max doesn't


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...