samedi 28 juillet 2018

Selenium not inputing strings based on name?

Im trying to create some tests in C# visual studio with selenium. When I run the test, google chrome navigates to the specified website, however no keys/strings are entered into the username and password fields...

Why is this? How do I fix this? How can I create a test which has the user enter the correct username and password queries and click on the submit form.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;


namespace test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            IWebDriver driver = new ChromeDriver("/Users/name/Desktop/test/");

            driver.Navigate().GoToUrl("http://newtours.demoaut.com/mercurywelcome.php");

            IWebElement username = driver.FindElement(By.Name("userName"));
            username.SendKeys("mercury");

            IWebElement password = driver.FindElement(By.Name("password"));
            password.SendKeys("mercury");

            var signIn = driver.FindElement(By.Name("login"));
            signIn.Submit();


        }
    }
}

Aucun commentaire:

Enregistrer un commentaire