I am trying this:
String str = "//*[@id="Result"]/h2";
WebElement vele = driver.findElement(By.cssSelector(str));
String vin = vele.toString();
System.out.println("Vin is"+vin);
The result is:
[[FirefoxDriver: firefox on WINDOWS (dcb60bbf-03e4-40df-8985-fbb35a988add)] -> css selector: #Result > h2]
I should get result as:
2G3AM51N6M2768439
My HTML code is:
<document>
<html>
<head>
<body>
<script language="javascript">window.onload = showLoad('random', 'random');</script>
<form method="post" action="" name="input">
<div id="container">
<input id="button" class="random" type="button" value="Generate Random VIN" onclick="showResult('random', 'random')" name="mk_vin"/>
<span id="Result">
<h2>2G3AM51N6M2768439</h2>
</span>
<hr/>
<input id="vin" class="verifybox" type="text" maxlength="17" value="" name="vin"/>
<input id="button" type="button" value="Verify VIN" onclick="showResult('verify', document.getElementById('vin').value)" name="ck_vin"/>
</div>
<div id="about">
<div id="footer" style="display: none;">
</form>
</body>
</html>
</document>