-1

I have 4 different fields (EMail, Mobile,Country, Mail Address). Now i have the values for each of them but just want to know what is the best practice to Verfiy all 4 in C#. (I know i can verify them one by one, but is there any other shortcut way with any loop logic ?

vic
  • 217
  • 1
  • 7
  • 18
  • _One by one_ and _loop logic_. Any loop in any programing language, will check values _one by one_ only. Can you explain bit more with some code snippet for what exactly you want to achieve? – MKay Nov 18 '15 at 06:28
  • Or may be I misunderstood the bracketed text in your question. – MKay Nov 18 '15 at 06:33
  • @mk08 1) First login and update contact details 2) Log out 3) Now login with same details and go to update contact details page and see values you have entered is the same in those text boxes. I'm already getting values stored from scenario.context to the step of validation But question is how should i validate them. I dont want to create separate method for all 4 values to verify which will look ugly because only difference will be xpath for all and the values to it . – vic Nov 18 '15 at 22:14

1 Answers1

-1

You can make two lists one is for your values to enter and the second one for WebElement. For fields you can use the same attribute of fields such as they should have same class, or you can write css selector to find 4 fields then iterate over the list and enter text. See the example below then convert it to your needs:

List<WebElement> fields = driver.FindElements(By.cssSelector(".class_name"));
String[] values = {"test@gmail.com", "7928346274", "UK", "bla bla no:45"};

for (int i=0; i < fields.Length; i++){
    fields[i].sendKeys(values[i]);
    // write your code ...
}
Mesut GUNES
  • 7,089
  • 2
  • 32
  • 49
  • @vic try it? downvoter what was the wrong with this? please give an explanation? – Mesut GUNES Nov 18 '15 at 08:28
  • :- I dont want to send the keys vaules are already entered . Scenario is like this 1) First login and update contact details 2) Log out 3) Now login with same details and go to update contact details page and see values you have entered is the same in those text boxes. I'm already getting values stored from scenario.context to the step of validation But question is how should i validate them. I dont want to create separate method for all 4 values to verify which will look ugly because only difference will be xpath for all and the values to it . – vic Nov 18 '15 at 22:12
  • 1
    @vic instead of 'sendKeys' use '.text' or '.getText' to get text then check it. Here is not a platform for ordering a code. – Mesut GUNES Nov 18 '15 at 23:57
  • I know what this platform is all about and i dident asked for code . as you can see it from my comment that there is not way i can able to find the same class for all the values as per my example . So your solution is good but that will not suite with my scenario. anyways i managed to solve it by creating separate method for validating and calling it for all 4 values. Now you let me know if you need code ? i can able to give you code which will give more sense. Thanks – vic Nov 20 '15 at 00:16
  • @vic I dont need the code solves your problem but someone may need it. If you think it is a good solution write your code as an answer. – Mesut GUNES Nov 20 '15 at 00:28