iterate through classes in selenium python
<p>** Im running this on a popup page. therefore cant simply use "entry" class as it clashes with the original page.</p>

<p>I want to iterate through classes to pick out the text, from the "entry" class</p>

<pre><code>from selenium import webdriver
driver=webdriver.Firefox()
</code></pre>

<p><a href="https://i.stack.imgur.com/Llbhu.png" rel="nofollow"><img src="https://i.stack.imgur.com/Llbhu.png" alt="enter image description here"></a></p>

<p>When I pick the xpath of this elemnt from chrome , its coming like this</p>

<p>But this isnt working with <code>driver.find_element_by_xpath(/html/body/span/div[1]/div/div[3])</code></p>

<p>But below one is working, but its giving me date, heading etc. But I just want the text</p>

<pre><code>driver.find_element_by_class_name("ui_overlay").text 
</code></pre>

<p>Try this xpath it will locate correctly : </p>

<pre><code>".//span[@class = 'ui_overlay ui_modal ']//div[@class='entry']" 
</code></pre>

<p>Example use:</p>

<pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome("C:\Jars\chromedriver.exe")
driver.maximize_window()
url="https://www.tripadvisor.com/Airline_Review-d8729164-Reviews-Cheap-Flights-TAP-Portugal#REVIEWS"
driver.get(url)

wait = WebDriverWait(driver, 10)

langselction = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.sprite-date_picker-triangle")))
langselction.click()
driver.find_element_by_xpath("//div[@class='languageList']//li[normalize-space(.)='Portuguese first']").click()
gt= driver.find_elements(By.CSS_SELECTOR,".googleTranslation&gt;.link")
for i in gt:
    i.click()
    time.sleep(2)
    x = driver.find_element(By.XPATH, ".//span[@class = 'ui_overlay ui_modal ']//div[@class='entry']")
    print x.text
    driver.find_element_by_class_name("ui_close_x").click()
    time.sleep(2)
</code></pre>

<p>It will print the corresponding text</p>

python selenium web-scraping