如何在浏览器最小化时使用 selenium webdriver 执行测试 [英] How to execute tests with selenium webdriver while browser is minimized

查看:193
本文介绍了如何在浏览器最小化时使用 selenium webdriver 执行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着运行这个程序.它适用于代码,但是当我最小化浏览器时,会弹出错误.程序似乎无法找到该按钮.有什么我可以用来修复它的.帮助

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

推荐答案

当您通过 Selenium 启动测试执行时,通常是浏览器最大化模式下启动.现在,要执行您的程序/脚本,Selenium 需要关注浏览器客户端上呈现HTML DOM.当测试执行处于进行中时,如果用户手动强制最小化浏览器,Selenium 将失去焦点并且在任何时间点都会引发异常,从而停止测试执行.

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.

您可以在Selenium 在浏览器被手动中断时停止的详细讨论

WebDriver 使用浏览器内置的自动化支持直接驱动浏览器.WebDriver 尝试尽可能接近地模拟用户体验和操作,并使用每个浏览器对自动化的本机支持直接调用浏览器.用户体验建模需要一定的设计、技术和与元素交互的支持.这些交互及其支持的功能取决于您使用的浏览器.简而言之,如果浏览器最小化,很可能 Selenium 将无法工作,因为在浏览器窗口最小化时用户无法与网页进行交互.

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.

您可以在 Selenium - 为什么最小化的浏览器会给出未找到元素的错误而max 不会

这篇关于如何在浏览器最小化时使用 selenium webdriver 执行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆