按钮是可单击的,但不会进入下一页-Selenium

时间:2018-09-05 07:52:34

标签: c# selenium selenium-webdriver xpath webdriver

单击按钮时遇到问题。我有多种情况,在每种情况下,我都应单击此按钮,当我单击此按钮时,应带我到另一页。我多次运行测试时,此按钮随机失败。例如:我对所有场景都进行了单元测试,但是其中一个失败了,我重复了所有场景的测试,但是我有一个新的失败场景

此错误是因为按钮未重定向到下一页

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>

1 个答案:

答案 0 :(得分:-1)

根据您与元素上的click()共享的html,文本为继续,您可以使用以下解决方案:

  • XPath

    new WebDriverWait(driver, TimeSpan.FromSeconds(time)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//button[@class='btn custom-btn custom-blue'][normalize-space()='Proceed']"))).Click();