Get Text from Span returns empty string
<p>I'm trying to get the text from the span inside this div with python and selenium:</p>

<pre><code>&lt;div class="product-name"&gt;
    &lt;span class="h1" itemprop="name"&gt;TEXT&lt;/span&gt;
&lt;/div&gt;
</code></pre>

<p>I've tried this, however, this returns an empty string:</p>

<pre><code>line = dr.find_element_by_class_name('product-name').find_element_by_xpath('.//span').text
</code></pre>

<p>Thanks in advance,</p>

<p>You should try using <code>css_selector</code> to find desire element in one find statement as below :-</p>

<pre><code>line = dr.find_element_by_css_selector('div.product-name &gt; span').text
</code></pre>

<p>If you're still getting empty string try using <code>get_attribute("textContent")</code> as :-</p>

<pre><code>line = dr.find_element_by_css_selector('div.product-name &gt; span').get_attribute("textContent")
</code></pre>

<p>Or using <code>get_attribute("innerHTML")</code> as :-</p>

<pre><code>line = dr.find_element_by_css_selector('div.product-name &gt; span').get_attribute("innerHTML")
</code></pre>

<p><strong>Note</strong> :- You can also use above operation to getting innerText on parent <code>&lt;div&gt;</code> element using <code>class_name</code> if there is only desire text as :-</p>

<pre><code>line = dr.find_element_by_class_name('product-name').text
</code></pre>

<p>Or</p>

<pre><code>line = dr.find_element_by_class_name('product-name').get_attribute("textContent")
</code></pre>

python selenium web-scraping phantomjs