Возникла следующая проблема (используется Firefox 51, Selenium IDE 2.9, Visual Studio 2015)
Записал простой тест: логин и логаут на сайте.
Если запуск производится в Selenium IDE, то все ОК.
Запускаю через Visual Studio. Ошибка
Result StackTrace:
в OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
в OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
в OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
в OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByLinkText(String linkText)
в OpenQA.Selenium.By.<>c__DisplayClass6.<LinkText>b__4(ISearchContext context)
в OpenQA.Selenium.By.FindElement(ISearchContext context)
в OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
в SeleniumTests.Untitled.TheUntitledTest() в C:\Users\Александр\Source\Repos\first_testing\adressbook-web-tests\adressbook-web-tests\UnitTest3.cs:строка 55
Result Message: OpenQA.Selenium.NoSuchElementException : Unable to locate element: Выход
Если пройти в режиме отладки пошагово, то все ОК. Тест зеленый.
Никак не могу понять почему элемент по шагам находится, а при полном прогоне нет.
Ниже код теста
P.S. Если вопрос обсуждался уже, то подскажите где посмотреть. Поиском не нашел.
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace SeleniumTests
{
[TestFixture]
public class Untitled
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "http://software-testing.ru/";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheUntitledTest()
{
driver.Navigate().GoToUrl(baseURL + "/forum/");
driver.FindElement(By.Id("sign_in")).Click();
driver.FindElement(By.Id("ips_username")).Click();
driver.FindElement(By.Id("ips_username")).Clear();
driver.FindElement(By.Id("ips_username")).SendKeys("*****");
driver.FindElement(By.Id("ips_password")).Click();
driver.FindElement(By.Id("ips_password")).Clear();
driver.FindElement(By.Id("ips_password")).SendKeys("*****");
driver.FindElement(By.Id("inline_remember")).Click();
driver.FindElement(By.CssSelector("input.ipsButton")).Click();
driver.FindElement(By.LinkText("Выход")).Click();
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
private bool IsAlertPresent()
{
try
{
driver.SwitchTo().Alert();
return true;
}
catch (NoAlertPresentException)
{
return false;
}
}
private string CloseAlertAndGetItsText()
{
try
{
IAlert alert = driver.SwitchTo().Alert();
string alertText = alert.Text;
if (acceptNextAlert)
{
alert.Accept();
}
else
{
alert.Dismiss();
}
return alertText;
}
finally
{
acceptNextAlert = true;
}
}
}
}