shalini shalini - 1 month ago 8
Python Question

Issues clicking an element using selenium

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..

Answer

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.