Can someone help me extract the value of h1 as a string using selenium?
Check out the HTML javascript snippet below-
<script type="text/javascript">
$(window).load(function() {
var $windowHeight = $(window).height() -12;
$("#top").height($windowHeight);
$('h1').css({
'margin-top' : (($windowHeight) - $('h1').outerHeight())/2,
'margin-bottom' : (($windowHeight) - $('h1').outerHeight())/2,
'opacity' : '1.0',
'filter' : 'alpha(opacity = 100)',
});
$("#container").click(function(){
$("html, body").animate({
scrollTop: $windowHeight + 50
}, 1500);
})
});
$(window).on("debouncedresize", function( event ) {
var $windowHeight = $(window).height() -12;
$("#top").height($windowHeight);
$('h1').css({
'margin-top' : (($windowHeight) - $('h1').outerHeight())/2,
'margin-bottom' : (($windowHeight) - $('h1').outerHeight())/2
});
});
</script>
For extracting h1 value in JAVA, here is what I have so far-
WebDriver driver = new FirefoxDriver();
driver.get("view-source:http://websitename.com/");
Thread.sleep(3000);
JavascriptExecutor js = null;
if (driver instanceof JavascriptExecutor) {
js = (JavascriptExecutor)driver;
}
js.executeScript("h1");
I'm not sure if JavaScriptExecutor is the right approach for this task. Any suggestions or guidance would be greatly appreciated. Thank you!