Compare string[] with string

Asked

Viewed 231 times

-3

I tried so:

IWebElement descriptionTextXPath = driver.FindElement(By.XPath("html/body/div[1]/div[1]/div[2]/div/ng-include[1]/section/ul/li[1]/div/div/article/h4"));
            String h4 = descriptionTextXPath.Text;
            Assert.AreEqual("Controle\n" + "Básico", h4);

Return:

Message:Assert.AreEqual.Failed
Expected:<Controle Básico>.Atual:<Controle Básico>

The intention is to affirm that the "Basic Control" exists on the screen. It follows the html structure where it is:

<h4 class="simulation-plan-name ng-binding">

Controle 
<span class="simulation-plan-type ng-binding">Básico</span>
</h4>

I tried to be as clear as I could, can you please help me ?

  • I don’t understand what you want to buy. Put an example of what you tried and the expected result.

  • 1

    is like asking how to compare a int[] (ex: {1, 2, 3}) with a int (ex: 1). They can’t be compared, they’re different. You have to convert the int[] in a int, or the other way round.

  • Ever tried to make a String words = s.Split(' ').Join(""); and compare with the descriptionTextXPath ?

  • So I want to make an assertion and see if they’re exactly the same, "Basic Control" that’s on the screen and "Basic Control" that I created. But the assertion does not work. If the case, it is to leave two types equal String - String. How would I do that and what I would use to verify that the equality condition is true ?

  • Here’s what I tried: Iwebelement h4element = driver.Findelement(By.Xpath("html/body/div[1]/div[1]/div[2]/div/ng-include[1]/Section/ul/li[1]/div/div/article/H4")); String descriptionTextXPath = h4element.Text; String s = "Basic Control"; String[] words = s.Split(' '); I don’t know what I would use in this case, but I tried Assert.Areequals(words,descriptionTextXPath); But it didn’t work.

  • If you want to make both guys equal string it makes no sense to make String[] words = s.Split(' ');.

  • @Andersonalves please edit your question and put the code in it. In the comments it is practically impossible to understand.

  • I tried: String s = "Basic Control"; String words = s.Split(' '). Join("); Points out the following error: 'System.Array' does not contain a Definition for 'Join' and Extension method 'Join' Accepting of type 'System.Array' could be found (are you Missing a using Directive or an Assembly Reference ?) I tried to declare with using System.Array; .

  • In short, I want to compare these two guys: String descriptionTextXPath = h4element.Text; String[] words = s.Split(' '); .

  • The question is': how do you want to convert a string array to a string? If the string array is { hello, world }, what should be the result? This is a question for you, not for us. So' you know how you want to make the comparison.

  • String s = "Basic Control"; String[] words = s.Split(' '); Console.Writeline(words);

  • Iwebelement h4element = driver.Findelement(By.Xpath("html/body/div[1]/div[1]/div[2]/div/ng-include[1]/Section/ul/li[1]/div/div/article/H4"); String descriptionTextXPath = h4element.Text; Console.Writeline(descriptionTextXPath); String s = "Basic Control"; String[] words = s.Split(' '); foreach (string word in words) { Console.Writeline(word); } // Personal I put inside this foreach and turned to string the two values are equal "Basic Control" with line break. It remains to be seen how I compare now?

  • Iwebelement descriptionTextXPath = driver.Findelement(By.Xpath("html/body/div[1]/div[1]/div[2]/div/ng-include[1]/Section/ul/li[1]/div/div/article/H4")); String H4 = descriptionTextXPath.Text; Assert.Areequal("Control n" + "Basic", H4);

Show 8 more comments

1 answer

2

Well, I still don’t know if I can figure out what you need to do, but I just assumed that you want to compare the value you have in a string with all the values of a array de string.

To do this, you must use the method static string.Join() for unite all values of array in a string and then compare it to the value already on string.

The method string.Join() receives as first parameter the array values separator and as according to parameter the array whose values you intend to "merge".

string[] arrStr = {"Controle", "Básico"};
string str = "Controle Básico";
var str2 = string.Join(" ", arrStr);

if(str == str2)
    //Essa condição será verdadeira

Browser other questions tagged

You are not signed in. Login or sign up in order to post.