0

I'm new using selenium. I am with some issues. I need to get the text or value of an element, but it isn't showed in HTML code.

For example, in this site (https://www.primefaces.org/showcase/ui/input/inputText.xhtml?jfwid=ec4b4) if I type something in the first input text, the text/value isn't showed in HTML code, so I can't assert it.

enter image description here

Can someone help me?

vitaliis
  • 4,082
  • 5
  • 18
  • 40

3 Answers3

1

Please try with the below code. It worked for me.

    driver.get("https://www.primefaces.org/showcase/ui/input/inputText.xhtml?jfwid=27a6e");     
    WebElement textfield = driver.findElement(By.id("j_idt302"));
    textfield.sendKeys("selenium");
    System.out.println(textfield.getAttribute("value"));
arpita biswas
  • 144
  • 1
  • 6
0

Try getting field's attribute named value:

driver.findElement(By.cssSelector(input[id=j_idt302])).getAttribute("value");

I had a similar question once Finding shadow DOM text with selenium and CSS

vitaliis
  • 4,082
  • 5
  • 18
  • 40
0

Try this xpath driver.findElement(By.xpath(".//input[@id='username2']")).getAttribute("value")

itronic1990
  • 1,231
  • 2
  • 4
  • 18