How to retrieve the second text in a validation with AssertEquals

0

I have this code:

AndI'mtryingtoretrievethetext"AutoTest".

I made the following code here.

WebElement idMenu = navegador.findElement(By.id("dropdown-menu-profile"));
String valortesteAutomacao = idMenu.getText();
assertEquals("Teste_Automacao", valortesteAutomacao);

but it only appears to me:

I have already tried Xphat, but it does not return ....

How to do it?

    
asked by anonymous 15.09.2018 / 16:21

2 answers

0

Your search is incorrect, when capturing by the dropdown-menu-profile id you are getting the entire text of the div. To get only the text of the paragraph you would need to be more specific, taking the child elements of the div or else using the xpath . Xpath example:

//div[@id='dropdown-menu-profile']//p
    
15.09.2018 / 17:12
0

I was able to do:

It's the following, in case, I had to navigate between all the Parents, to get onte wanted. So I used 3 types of By (id, className, tagName). I just did not know about the tagName, which was what I was missing before. So I did not have to use xPhat.

WebElement testeAutomacao = navegador.findElement(By.id("dropdown-menu-profile"));
WebElement idMenu = testeAutomacao.findElement(By.className("user-data"));
String valortesteAutomacao = idMenu.findElement(By.tagName("p")).getText();
assertEquals("Teste_Automacao", valortesteAutomacao);
idMenu.click();
    
18.09.2018 / 01:30