0

For example this simple HTML5 form https://demoqa.com/automation-practice-form

Click Submit, then driver.findElement(By.id("firstName")).getAttribute("class") would not return ":invalid".

Impossible without JavaScript calls?

Screenshot

Alexei Vinogradov
  • 1,548
  • 3
  • 15
  • 34

1 Answers1

0

Might be possible using the javascript executor: http://infiautomation.blogspot.com/2019/07/working-with-pseudo-elements-in.html

String script = "return window.getComputedStyle(document.querySelector('#test_ID'),':invalid').getPropertyValue('border-color')";
JavascriptExecutor js = (JavascriptExecutor)driver;
String content = (String) js.executeScript(script);
System.out.println(content);

It's really checking the styling rather than if the attribute psuedo class exists. Much like this answer here: https://stackoverflow.com/a/53868324/1387701

var el = document.querySelector('#elt'),
pseudo = window.getComputedStyle(el, ':before');
alert(pseudo.getPropertyValue("content"));
DMart
  • 2,401
  • 1
  • 14
  • 19