In the if-else statement, the program shows the error
no such element: Unable to locate element: {"method":"xpath","selector":"//a[contains(.,'Frizerul')]/ancestor::div[contains(@class, 'js-answer-element')]//div[@class='sg-actions list__hole']//li[2]//span[contains(.,'raportată ca abuz')]"}
and doesn't execute the else (in this case showing a message in console)
The method is:
public void reported(String username){
if(driver.findElement(By.xpath("//a[contains(.,'"+username+"')]/ancestor::div[contains(@class, 'js-answer-element')]//div[@class='sg-actions-list__hole']//li[2]//span[contains(.,'raportată ca abuz')]")).isDisplayed()==true)
{
System.out.println ("Tema raportata " + driver.getCurrentUrl());
}
else{
System.out.println ("Tema nneraportata"+driver.getCurrentUrl());
}
}
Can anyone explain me what I am doing wrong?