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

查看:219
本文介绍了使用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自动更新所需的扩展程序. 在默认的Google Chrome浏览器中找到文件"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*\AppData\Local\Google\Chrome\User Data\Default\Extensions

在其中找到您的扩展程序的更新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 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天全站免登陆