如何在不重新启动 webdriver 的情况下动态更新 Selenium 方法? [英] How to dynamically update Selenium methods without restarting the webdriver?

查看:66
本文介绍了如何在不重新启动 webdriver 的情况下动态更新 Selenium 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Selenium 机器人,它可以与 EA Sports FIFA 21 网络应用程序交互,您可以在其中买卖游戏中的足球运动员.界面看起来像this.

I have a Selenium bot that interacts with EA Sports FIFA 21 web app, where you can buy and sells in-game football players. The interface looks like this.

假设我的原始程序是一个单一的脚本:

Lets say my original program was a single script that:

  1. login() - 登录平台
  2. goToTransferMarket() - 导航到市场搜索"页面
  3. inputSearchParameters(playername) - 输入我的搜索参数进行搜索
  4. clickSearch() - 单击搜索"按钮
  5. evaluateResults(buy_price) - 评估结果并购买比购买价格便宜的球员

如果任何方法失败,我都必须退出并从头开始.为了解决这个问题,我构建了一个 tkinter GUI,其中包含用于在它们中执行的每个功能的按钮自己的线程.这样,如果某个功能失败,比如点击搜索按钮,我可以手动执行该操作并继续测试后续方法.

If any method failed, I’d have to quit and restart from scratch. To fix this, I built a tkinter GUI with buttons for each function that executes in their own thread. This way If a function fails, like clicking the search button, I can manually perform the action and proceed to test the subsequent methods.

但是,为了修复损坏的方法,我必须从头开始重新启动程序,这需要繁琐的登录过程来修复像忘记将字符串转换为整数这样简单的问题.大量登录也会引起不必要的注意.

But still, to fix the broken methods, I have to restart the program from scratch which requires a tedious login process to fix something as simple as forgetting to cast a string to an integer. Logging in a lot also draws unwanted attention.

鉴于我在当前测试会话期间已经登录,是否有办法重新编译我的程序并抓取"现有的 webdriver 会话?

更好的是,是否可以动态更改我的功能并在我的 GUI 中使用使用最新代码更新"按钮来更新它们?

我的 GUI 中的玩家列表"框写入一个文本文件,它允许我实时更改机器人正在搜索的人.当我单击使用列表出价"时,文本文件将传递给主要的机器人搜索方法.按钮.这让我想知道我是否可以设置它以某种方式在单独的线程中重新编译我的代码的一部分并保留我现有的 webdriver 会话.任何帮助都会很棒,谢谢.

The 'player list' box in my GUI writes to a textfile, which allows me to change who the bot is searching for in real time. The textfile is passed to the main bot search method when I click the "Bid using list" button. This is what made me wonder if I can set it up to somehow recompile parts of my code in a separate thread and keep my existing webdriver session. Any help would be amazing thank you.

推荐答案

您可以添加一个无限的 while 循环并尝试 catch 以确保您的测试永远不会失败 else :

You can add a infinite while loop and try catch to make sure your test never fails else :

如果您使用的是 chrome :

If you are using chrome :

您可以使用调试器地址连接到现有的 chrome 会话,因此从 cmd 使用指定的调试端口启动 chrome

you can connect to existing chrome session using debuuger address, so start the chrome with specified debugging port from cmd

用调试端口启动chrome:(在windows中搜索其他操作系统如何在特定调试端口启动chrome)

Start chrome with debug port: (In windows , search for other os how to start chrome in a specific debug port)

\chrome.exe"--remote-debugging-port=1559

在硒中使用:

Java:

System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

ChromeOptions options = new ChromeOptions();

options.setExperimentalOption("debuggerAddress", "127.0.0.1:1559");

WebDriver browser=new ChromeDriver(options);`

蟒蛇:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:1559")
driver = webdriver.Chrome(options=chrome_options)

这篇关于如何在不重新启动 webdriver 的情况下动态更新 Selenium 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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