How to verify placeholder text using selenium webdriver and javascript?



  • How can I verify this type of error message that uses placeholder text, put there by javascript?

    enter image description here



  • A Message like this will probably create a new div so, if there is really no other way to identify it, you could use something along the lines of

    List Elements = driver.findElements(By.tagName("div"));
    Boolean ElementExists = false;
    for(counter = 0, counter < Elements.size(); counter++){
        if(Elements.get(counter).getText().equals("The Popup text"){
            ElementExists = true;
        }
    }
    

    This iterates through every div on your site gets the displayed text and sets the Boolean true if it finds an element with the desired text. This solution is exceptionally crude (and worse, slow) but it should be able to do the job. If you'd send a link to the Site I'd look if I can find a better solution.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2