How to execute tests with selenium webdriver while

2020-04-12 10:01发布

问题:

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

回答1:

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