Organizational Research By

Surprising Reserch Topic

webdriver enters wrong text in wrong input elements using -'c#,c#-4.0,selenium-webdriver,nunit,pageobjects'

webdriver enters wrong text in wrong input elements  using -'c#,c#-4.0,selenium-webdriver,nunit,pageobjects'

I'm using selenium to test a webapp.
It has to do with adding Announcements/data. It has alot of inputs...

Problem: Randomly, text-A, meant for input-A get typed in input-B as well as text-B.

Since there's a lot of repetition, I read text-inputs from xml and return a dictionary. And type text as so

public AnnouncementAdvertiserFields TypeAdvertiserFields(string pathToXml)
        var xmlParser = new XmlParser();
        Dictionary<string, string> fields = xmlParser.TypeAdvertiserFieldsFromXml(pathToXml);

        string name;
        string coAddress;
        string streetName;
        string streetNo;
        string streetFloor;
        string streetDoor;
        string city;
        string postalCode;
        string postalCity;
        string phoneNo;
        string mobileNo;
        string faxNo;
        string country;
        string journalNo;

        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.Name, out name);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.CoAdress, out coAddress);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.Streetname, out streetName);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.StreetNumber, out streetNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.StreetFloor, out streetFloor);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.StreetDoor, out streetDoor);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.City, out city);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.PostalCode, out postalCode);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.PostalCity, out postalCity);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.PhoneNumber, out phoneNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.MobilePhoneNumber, out mobileNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.FaxNumber, out faxNo);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.Country, out country);
        fields.TryGetValue(WebTesting.Common.Constants.AdvertiserFieldNames.JounalNo, out journalNo);

        if (name != string.Empty) TypeName(name);
        if (coAddress != string.Empty) TypeCoAddress(coAddress);
        if (streetName != string.Empty) TypeStreetName(streetName);
        if (streetNo != string.Empty) TypeStreetNumber(streetNo);
        if (streetFloor != string.Empty) TypeStreetFloor(streetFloor);
        if (streetDoor != string.Empty) TypeStreetDoor(streetDoor);
        if (city != string.Empty) TypeCity(city);
        if (postalCode != string.Empty) TypePostalCode(postalCode);
        if (postalCity != string.Empty) TypePostalCity(postalCity);
        if (phoneNo != string.Empty) TypePhoneNumber(phoneNo);
        if (mobileNo != string.Empty) TypeMobilePhoneNumber(mobileNo);
        if (faxNo != string.Empty) TypefaxNumber(faxNo);
        if (country != string.Empty) SelectCountryByValue(country);
        if (journalNo != string.Empty) TypeJournalNumber(journalNo);
        return this;

Example of TypeName from AnnouncementAdvertiserFields

public void TypeName(string name)
 TypeText(name, _nameInputLocator);

TypeName calls generic TypeText method from a superclass.

protected void TypeText(string text, By locator)

Type AnnouncementAdvertiserFields is a property on the page object page of the specific announcement type.

I have tried using both implicit wait and explicit wait. With sooooooo many combinations of ExpectedConditions

TextToBePresentInElement before and after SendKeys

I would think code like this should work

var wait = new WebDriverWait(Webdriver, TimeSpan.FromSeconds(5));
var element = Webdriver.FindElement(locator);
wait.Until(ExpectedConditions.TextToBePresentInElement(element, ""));
Wait.Until(ExpectedConditions.TextToBePresentInElement(FindStdkElement(locator), text));

I also tried using the SelectElement but to no avail.

If I debug my way through, everything is dandy and great. No errors. But when I run the test, sometimes it passes other times fails. I cannot find any system as to which fields fails. It's random...

When I run the tests from my local machine I have no issues. But when run from machine in DEV, they fail sporadically. DEV-machine is less powerfull than local, which makes my think it might be a timing issue. That maybe Selenium is is typing to fast for the browser to keep up.

I use Nunit as testframework. With ReSharper.

Any help or directions will be much appreciated. thanks guys

asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.