There is a form with user authorization fields: screenshot

I would like to test it with the help of Selenium. I came across such an example on the web (below is the code fragment):

@Test public void inValid_UserCredential() { System.out.println("Starting test " + new Object(){}.getClass().getEnclosingMethod().getName()); driver.get("http://192.168.35.10/"); driver.findElement(By.xpath(".//*[@id='account']/a")).click(); driver.findElement(By.id("E-Mail")).sendKeys("testuser"); driver.findElement(By.id("Passwort")).sendKeys("Test@123"); driver.findElement(By.id("login")).click(); try{ element = driver.findElement (By.xpath(".//*[@id='account_logout']/a")); }catch (Exception e){ } Assert.assertNotNull(element); System.out.println("Ending test " + new Object(){}.getClass().getEnclosingMethod().getName()); } 

As I understand it, this fragment enters incorrect data into the fields and clicks. However, the question is as follows. The test does not work as it should for fields of the type I showed in the screenshot and I think that here is By.id("E-Mail") error. It is necessary that he somtrel not by id, but by some other parameter (to find these fields and enter in them what is shown in parentheses). Do I understand this correctly and if so, what should I change to correct this error?

  • one
    Understanding is correct. Open the DOM and look at your component - Andrew Bystrov
  • I'm not a very experienced person in this topic, but what is a DOM? - Iga
  • one
    read this topic seleniumhq.org/docs/… - Andrew Bystrov
  • Many thanks, that is necessary. and another question arose. what this line with the regularity 'driver.findElement (By.xpath (".//*[@ id =' account '] / a")) means. click (); ' - Iga
  • one
    This is not quite regular, this is how xpath is described. You can read about it here w3schools.com/xsl/xpath_intro.asp - Andrew Bystrov

0