【发布时间】:2017-03-04 08:42:19
【问题描述】:
所以我在与下面的 HTML 交互时遇到了问题。我无法使用不同的 Selenium Webdriver 命令打开和关闭弹出窗口。虽然我在这里寻找一个特定的解决方案,但任何有关处理 Angular JS 的一般提示也将不胜感激。我认为问题的根本原因是我不知道使用 Selenium Webdriver 自动化 Angular 的好方法。
我正在使用 C#,但我会从任何编程语言中获取任何有用的信息,因为我可以随时改进解决方案。
我正在尝试与此弹出按钮交互,但未成功: uib-popover-template="'/app/student/assessment/directives/templates/shortTextPopupTemplate.html'"
<div class="line ttsBorder">“<span style="font-style:italic;">And be it further enacted</span><span style="display: inline;">, That in all that territory ceded</span><span short-text-popup="" accession-number="VH209006" class="ng-isolate-scope" ng-non-bindable=""><a uib-popover-template="'/app/student/assessment/directives/templates/shortTextPopupTemplate.html'" popover-is-open="ctrl.isVisible" popover-trigger="none" popover-placement="auto top" tabindex="0" title="Shows more information." ng-click="buttonOnClick($event)" ng-keydown="buttonOnKeydown($event)" ng-class="['stpu-button', {disabled: ctrl.isDisabled, active: ctrl.isVisible}]" class="ng-scope stpu-button" style="z-index: 3;"></a></span> by France to the United States&nbsp;.&nbsp;.&nbsp;.&nbsp;which lies north of thirty‑six degrees and thirty minutes north latitude&nbsp;.&nbsp;.&nbsp;.&nbsp;slavery&nbsp;.&nbsp;.&nbsp;.&nbsp;shall be, and is hereby, forever prohibited.”</div>
这是我尝试失败的方法:
//attempt 1
var elements = Driver.FindElements(By.XPath("//*[@class='line ttsBorder']"));
//attempt 2 - UserInteractions = new Actions(Driver);
UserInteractions.MoveToElement(PopUpButton).Click().Perform();
//attempt 3
Driver.FindElement(By.XPath("//[@title='Shows more information.']")).Click();
//attempt 4
//Driver.FindElement(By.XPath("//a[@uib-popover-template]"));
PopUpButton.Click();
//attempt 5
//Working, but seems dirty - JavaExecutor.ExecuteScript("arguments[0].click();", PopUpButton);
我不得不在 UI 中切换以找到我想要的元素。我对这样一个脆弱的解决方案感到非常不满,希望您能提供一些建议。
提前致谢!
【问题讨论】: