1

Im using this code to explore tripadvisor (Portuguese comments)

from selenium import webdriver
from bs4 import BeautifulSoup
driver=webdriver.Firefox()
driver.get("https://www.tripadvisor.com/Airline_Review-d8729164-Reviews-Cheap-Flights-TAP-Portugal#review_425811350")
driver.set_window_size(1920, 1080)

Then Im trying to click the google-translate link

driver.find_element_by_class_name("googleTranslation").click()

But getting this error :-

WebDriverException: Message: Element is not clickable at point (854.5, 10.100006103515625). Other element would receive the click: <div class="inner easyClear"></div>

So the div class="inner easyClear" is getting the click. I tried exploring it

from bs4 import BeautifulSoup
page=driver.page_source 
for i in page.findAll("div","easyClear"):
    print i
    print "================="

But was unable to get any intuition from this as in what changes to incorporate now to make the "Google Translate" clickable. Please help

===============================EDIT===============================

Ive also tried these

driver.execute_script("window.scrollTo(0, 1200);")
driver.find_element_by_class_name("googleTranslation").click()

Resizing the browser to full screen etc..

9
  • I don't see the element with googleTranslation class on the page - can you provide a screenshot of the element you want to click? Thanks. Commented Oct 9, 2016 at 4:22
  • The problem isn't that the element isn't in view, it's that it's contained by another element that will absorb the pointer event. Can you post a sample of the HTML of that div? Have you tried clicking that div, instead? Commented Oct 9, 2016 at 4:25
  • <div class="googleTranslation reviewItem"> <span class="link" onclick="ta.call('ta.overlays.Factory.reviewTranslate', event, this, '/MachineTranslation?g=1&amp;d=8729164&amp;r=425765103&amp;page=review&amp;sl=pt&amp;tl=en'); ta.trackEventOnPage('Reviews', 'google_translate')"> <img alt="Google Translation" src="static.tacdn.com/img2/buttons/googleTranslation.gif"> </span> </div> Commented Oct 9, 2016 at 4:27
  • @shalini Still don't see it - do you have a google translate extension installed may be?.. Commented Oct 9, 2016 at 4:32
  • @alecxe Ohh my bad, you have to clik on "Protuguese" first. That way it will show Portuguese comments & hence will have "Google Translate" widget along with each comment Commented Oct 9, 2016 at 4:35

1 Answer 1

2

What worked for me was to use an Explicit Wait and the element_to_be_clickable Expected Condition and get to the inner span element:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.tripadvisor.com.br/ShowUserReviews-g1-d8729164-r425802060-TAP_Portugal-World.html")

wait = WebDriverWait(driver, 10)

google_translate = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".googleTranslation .link")))

actions = ActionChains(driver)
actions.move_to_element(google_translate).click().perform()

You may also be getting into a "survey" or "promotion" popup - make sure to account for those.

Sign up to request clarification or add additional context in comments.

5 Comments

@vinita you should basically iterate over all review elements and search for the "googleTranslation" elements inside..
@alecxe I tried this but not working :- for i in driver.find_element_by_class_name("entry"): print i [ERROR : TypeError: 'WebElement' object is not iterable]
@shalini yeah, that's find_elements_by_class_name(), not find_element_by_class_name() - watch the s.
@alecxe can u pls help me with the iteration , it isnt working. for i in driver.find_elements_by_class_name("partial_entry"): wait = WebDriverWait(driver, 10) google_translate = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".googleTranslation .link"))) actions = ActionChains(driver) actions.move_to_element(google_translate).click().perform() driver.find_element_by_class_name("ui_close_x").click()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.