【发布时间】:2018-09-05 07:52:34
【问题描述】:
单击按钮时遇到问题。我有多个场景,在每个场景中我都应该点击这个按钮,当我点击这个按钮时应该把我带到另一个页面。当我多次运行测试时,此按钮随机失败。例如:我运行单元测试所有场景都有效,但其中一个失败了我重复测试所有场景都成功但我有一个新的失败场景
这个错误是因为按钮没有重定向到下一页
Message: Test method BnI.UITests.Register.CancelOfficialInfoTest threw exception:
OpenQA.Selenium.NoSuchElementException: Unable to locate element: (.//*[normalize-space(text()) and normalize-space(.)='Name:'])[1]/following::input[1]
我用来点击按钮的方法
new WebDriverWait(driver, TimeSpan.FromSeconds(time)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//button[contains(text(),'Proceed')]"))).Click();
HTML:
<div class="col-xs-12 no-padding-sides">
<div class="col-xs-8 col-xs-offset-4 no-padding-sides bottom-actions">
<button class="btn custom-btn custom-blue" type="submit">
Proceed
</button>
<button type="button" class="btn custom-btn custom-grey" (click)="cancelRegistration()"> Cancel </button>
</div>
【问题讨论】:
-
代码中的选择器与异常日志中的选择器不匹配。同样使用
WebDriverWait应该会导致TimeoutException,但不会导致NoSuchElementException。适当更新您的问题 -
这个错误是因为按钮没有重定向到下一页。
-
所以找到并点击了按钮,但它没有任何效果,对吧?试试
Submit()而不是Click() -
是的,你说的是正确的..我尝试提交相同的结果
-
提交前是否需要执行其他操作?比如填写一些输入字段等...如果是这样,您确定这些操作正确执行了吗?
标签: c# selenium selenium-webdriver xpath webdriver