ses ses - 1 year ago 219
Java Question

Selenium WebDriver getText

I have a

<div name="myDiv">0</div>

I try to write a test that myDiv has 0 text in it. With WebDriver it is:

String text = webDriver.findElement(By.xpath("//div[@name='myDiv']")).getText();

but in the result I have an empty string. Shouldn't I use getText() for getting a content of a div?

ses ses
Answer Source

I found an answer, I just need use real browser for my webDriver

webDriver = new FirefoxDriver();

then it works.

Maybe it is JavaScript issue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download