How to check the language of any text present on Website using Selenium
<p>I am testing a website which contains user reviews for hotels which can be in any lang...i.e, Czech or russian or spanish or english etc... and have a question about how can i check in which language the text is by reading the text using Selenium. </p>

<p>for example i am using to element.text method of selenium to read the text, then i want to place a check if its in english then do this else for any other language do that.</p>

<p>This is one of the html element</p>

<pre><code>&lt;div class="innerBubble"&gt;
&lt;div class="quote"&gt;&lt;a href="/ShowUserReviews-g1-d8729164-r427772133-TAP_Portugal-World.html#CHECK_RATES_CONT" onclick="ta.setEvtCookie('Reviews','title','',0,this.href); setPID();" id="r427772133"&gt;â&lt;span class="noQuotes"&gt;TRES SATISFAITS&lt;/span&gt;â&lt;/a&gt;&lt;/div&gt;
&lt;div class="rating reviewItemInline"&gt;
&lt;span class="rate sprite-rating_s rating_s"&gt; &lt;img class="sprite-rating_s_fill rating_s_fill s40" width="56" src="https://static.tacdn.com/img2/x.gif" alt="4 of 5 stars"&gt;
&lt;/span&gt;
&lt;span class="ratingDate relativeDate" title="October 13, 2016"&gt;Reviewed 3 days ago
&lt;span class="new redesigned"&gt;NEW&lt;/span&gt; &lt;/span&gt;
&lt;/div&gt;
&lt;div class="googleTranslation reviewItem"&gt;
&lt;span class="link" onclick="ta.call('ta.overlays.Factory.reviewTranslate', event, this, '/MachineTranslation?g=1&amp;amp;d=8729164&amp;amp;r=427772133&amp;amp;page=review&amp;amp;sl=fr&amp;amp;tl=en'); ta.trackEventOnPage('Reviews', 'google_translate')"&gt;
&lt;img alt="Google Translation" src="https://static.tacdn.com/img2/buttons/googleTranslation.gif"&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;div class="entry"&gt;
&lt;p&gt;
Un peu d'apprÃ©hension avant mais vite levÃ©e. TrÃ¨s bon accueil et bon service de la part des pnc, repas chaud et bon, mÃªme pour ce court vol (1h50). Bonne ponctualitÃ© et embarquement des plus efficaces
&lt;/p&gt;
&lt;/div&gt;
</code></pre>

<p>Here Nothing to do with selenium driver just get the text and use the below code
If you need to detect language in response to a user action then you could use <a href="http://code.google.com/apis/language/translate/v1/using_rest_langdetect.html" rel="nofollow">google ajax language API</a>:</p>

<pre><code>#!/usr/bin/env python
import json
import urllib, urllib2

def detect_language(text,
userip=None,
referrer="http://stackoverflow.com/q/4545977/4279",
api_key=None):        

query = {'q': text.encode('utf-8') if isinstance(text, unicode) else text}
if userip: query.update(userip=userip)
if api_key: query.update(key=api_key)

url = 'https://ajax.googleapis.com/ajax/services/language/detect?v=1.0&amp;%s'%(
    urllib.urlencode(query))

request = urllib2.Request(url, None, headers=dict(Referer=referrer))
d = json.load(urllib2.urlopen(request))

if d['responseStatus'] != 200 or u'error' in d['responseData']:
    raise IOError(d)

return d['responseData']['language']

print detect_language("Python - can I detect unicode string language code?")
</code></pre>

<p><strong>OUTPUT</strong></p>

<pre><code>en
</code></pre>

python selenium-webdriver