5
votes

I am working on Watir webdriver and I want to get text of the h1 tag of the page

<body class="not-front not-logged-in page-node node-type-first-drive one-sidebar sidebar-right col-2 bp col-2 lightbox-processed" data-twttr-rendered="true">
<div class="container">
<div id="header">
<div class=""></div>
<div class="col-center">
<h1>New Page header</h1>

The code that I am writing is

@title2 = @browser.h1.attribute_value "text"
    puts @title2

BUT the output that I am getting is Nil instead of "New Page header"

1

1 Answers

5
votes

Have you tried

puts @browser.h1.text

or

puts @browser.div(:class => 'col-center').h1.text