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

查看:118
本文介绍了在最小化浏览器的情况下如何使用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 启动测试执行时,通常是 Browser 最大化 模式启动.现在,要执行您的程序/脚本, Selenium 需要在 Browser Client 上具有 focus ,该焦点将呈现

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.

您可以在>手动中断浏览器时硒停止

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.

您可以在 查看全文

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