使用 selenium webdriver 自动单击 chrome://extensions 页面上的按钮 [英] Automate a button click on chrome://extensions page using selenium webdriver

查看:65
本文介绍了使用 selenium webdriver 自动单击 chrome://extensions 页面上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个自动化测试来自动化更新 google chrome 扩展程序的过程.我不知道另一种自动执行此操作的方法,所以这是我目前正在尝试做的:

I'm trying to write an automated test that will automate the process of updating a google chrome extension. I'm not aware of another method of doing this automatically so here is what I'm currently trying to do:

  1. 打开 chrome 扩展页面(据我所知,这只是一个 html 页面,除非我遗漏了什么).

  1. Open the chrome extensions page (as far as I'm aware this is just an html page unless I'm missing something).

点击更新扩展"按钮

这是我在打开 chrome 扩展页面后所尝试的:

Here is what I have tried having opened the chrome extensions page:

IwebElement UpdateButton = driver.findelement(By.Id("update-extensions-now"));
UpdateButton.Click();

由于某种原因,按钮单击未注册.我尝试了其他一些定位器,例如 CSS 路径和​​ Xpath,但它们也不起作用.另外,当我调试这个测试时,它通过了,所以我知道这不是我的任何定位器的问题.我(作为测试)尝试自动点击此页面上的其他元素,这是同样的问题.我根本无法处理 chrome://extensions 页面上的任何元素.

For some reason the button click is not registering. I have tried some other locators such as CSS path and Xpath but they don't work either. Also, when I debug this test, it passes fine so I know it's not an issue with any of my locators. I have (as a test) tried to automate clicks on the other elements on this page and it's the same issue. I can't get a handle on any elements on the chrome://extensions page at all.

有没有人遇到过这种情况或对发生了什么有任何想法?

Has anyone encountered this or have any ideas as to what's going on?

推荐答案

您可以使用 Chrome 扩展 API 来自动更新所需的扩展.在默认谷歌浏览器中找到文件manifest.json"

You can use the Chrome extensions API to auto-update required extension. Find the file "manifest.json" in the default Google Chrome

C:Users*UserName*AppDataLocalGoogleChromeUser DataDefaultExtensions

在那里找到你的扩展的更新 URL:

There find the update URL of your extension:

{
  "name": "My extension",
  ...
  "update_url": "http://myhost.com/mytestextension/updates.xml",
  ...
}

Google 服务器返回的 XML 如下所示:

The returned XML by the Google server looks like:

<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
  <app appid='yourAppID'>
    <updatecheck codebase='http://myhost.com/mytestextension/mte_v2.crx' version='2.0' />
  </app>
</gupdate>

应用程序扩展程序或应用程序 ID,基于公钥的哈希生成,如打包中所述.您可以通过转到扩展页面 (chrome://extensions) 找到扩展程序或 Chrome 应用程序的 ID.

appid The extension or app ID, generated based on a hash of the public key, as described in Packaging. You can find the ID of an extension or Chrome App by going to the Extensions page (chrome://extensions).

代码库.crx 文件的 URL.

codebase A URL to the .crx file.

版本客户端用于确定是否应下载代码库指定的 .crx 文件.它应该与 .crx 文件的 manifest.json 文件中的version"值匹配.

version Used by the client to determine whether it should download the .crx file specified by codebase. It should match the value of "version" in the .crx file's manifest.json file.

更新清单 XML 文件可以通过包含多个元素来包含有关多个扩展的信息.

The update manifest XML file may contain information about multiple extensions by including multiple elements.

另一个选项是使用 --extensions-update-frequency 命令行标志来设置更频繁的间隔(以秒为单位).例如,要让检查每 45 秒运行一次,请像这样运行 Google Chrome:

Another option is to use the --extensions-update-frequency command-line flag to set a more frequent interval in seconds. For example, to make checks run every 45 seconds, run Google Chrome like this:

chrome.exe --extensions-update-frequency=45

请注意,这会影响对所有已安装扩展程序和应用程序的检查,因此请考虑这对带宽和服务器负载的影响.您可能希望暂时卸载除您正在测试的那个之外的所有内容,并且在正常浏览器使用期间不应在打开此选项的情况下运行.

Note that this affects checks for all installed extensions and apps, so consider the bandwidth and server load implications of this. You may want to temporarily uninstall all but the one you are testing with, and should not run with this option turned on during normal browser usage.

更新每个单独的扩展的请求是:

The request to update each individual extension would be:

http://test.com/extension_updates.php?x=id%3DyourAppID%26v%3D1.1

您可以在 exntesions 开发者网站上找到更多详细信息:https://developer.chrome.com/extensions

You can find even more detailed information on exntesions developers site: https://developer.chrome.com/extensions

这篇关于使用 selenium webdriver 自动单击 chrome://extensions 页面上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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