【发布时间】:2019-02-06 08:31:57
【问题描述】:
我已经下载了最新的 rcx 文件,并在 chrome 选项中添加了扩展。
第一步执行得很好。第二步执行到 driver.Navigate().GoToUrl("chrome://extensions-frame/");
下一步它会抛出这个错误
"OpenQA.Selenium.NoSuchElementException
HResult=0x80131500
Message=no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class='extension-commands-config']"}
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath)
at OpenQA.Selenium.By.<>c__DisplayClass19_0.<xpath>b__0(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at Exsilio.QA.Test.DKNAccessabilityTest.AccessabilityTest() in C:\Trilok\Projects\Code\Automation Testing\RealTimeDataUpdate\QualityAssurance\Exsilio.QA.Test\DKNAccessabilityTest.cs:line 40"
我正在使用“extension_1_0_9_0.crx”作为当前扩展名。
请满足需要。
我的代码如下:
[TestInitialize]
public void Init()
{
//Open ChromeDriver with appropriate extension enabled
ChromeOptions options = new ChromeOptions();
options.AddExtension("../Extension/extension_1_0_9_0.crx");
driver = Driver.Initalize<ChromeDriver>(options);
}
[TestMethod]
public void AccessabilityTest()
{
// 2 - setup key shortcut for extension
driver.Navigate().GoToUrl("chrome://extensions-frame/");
driver.FindElement(By.XPath("//a[@class='extension-commands-config']"))
.Click();
driver.FindElement(By.XPath("//span[@class='command-shortcut-text']"))
.SendKeys(Keys.Control + "m");
driver.FindElement(By.Id("extension-commands-dismiss"))
.Click();
// 3
driver.Navigate().GoToUrl("http://www.google.pl");
// 4 - open WAVE extension
new Actions(driver).KeyDown(Keys.Control).SendKeys("m").Build().Perform();
// 5
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementExists(By.ClassName("wave5icon")));
// 6
var waveTips = driver.FindElements(By.ClassName("wave5icon"));
if (waveTips.Count == 0) Assert.Fail(
"Could not locate any WAVE validations - " +
"please ensure that WAVE is installed correctly");
foreach (var waveTip in waveTips)
{
if (!waveTip.GetAttribute("alt").StartsWith("ERROR")) continue;
var fileName = String.Format("{0}{1}{2}",
"WAVE", DateTime.Now.ToString("HHmmss"), ".png");
var screenShot = ((ITakesScreenshot)driver).GetScreenshot();
//screenShot.SaveAsFile(
// Path.Combine(System.IO.Path.GetTempPath(), fileName), ImageFormat.Png);
driver.Close();
Assert.Fail(
"WAVE errors were found on the page. Please see screenshot for details");
Assert.IsTrue(false, "One or more of the functionality tests failed : WAVE errors were found on the page. Please see screenshot for details");
}
//Assert.IsTrue(isAllPass, "One or more of the functionality tests failed");
}
【问题讨论】:
-
我没有尝试使用 Wave 实现这一点的任何方法。它对我不起作用。 Wave 只会为您提供错误的快照。而且从快照中,您将无法了解哪些是错误或缺陷的类型。我建议不要为可访问性测试使用 WAVE 扩展。而不是使用工具“Globant.Selenium.Axe”。使用 Nuget 包管理器安装插件并享受!
标签: c# selenium automation browser-automation