python - Selenium on mac gives elementNotVisibleException -


here test case:

#!/usr/bin/env python selenium import webdriver lxml.cssselect import cssselector import selenium.webdriver.support.ui ui import time  def test(urlx):      br = webdriver.phantomjs('phantomjs')     start_time = time.time()     br.get(url)     restaurant_url_sel = u'.restaurants a'     ta_restaurant_button = br.find_element_by_css_selector(restaurant_url_sel)      print str(ta_restaurant_button.text)      elapsed_time = time.time() - start_time     print("---|||||||||||||||||||||||||| %s seconds |||||||||||||||||||||||||||||||---" % elapsed_time)     print br.page_source   url = 'http://www.tripadvisor.com/tourism-g150812-playa_del_carmen_yucatan_peninsula-vacations.html' test(url) 

the traceback:

traceback (most recent call last):   file "scrapeall_destination.py", line 20, in <module> get_restaurants(url)   file "/users/pablocastelo/desktop/tripadvisor/get_restaurants.py", line 67, in get_restaurants ta_restaurant_button.click()   file "/library/python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 65, in click self._execute(command.click_element)   file "/library/python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 385, in _execute return self._parent.execute(command, params)   file "/library/python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 173, in execute self.error_handler.check_response(response)   file "/library/python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 166, in check_response   raise exception_class(message, screen, stacktrace) selenium.common.exceptions.elementnotvisibleexception: message: {"errormessage":"element not visible , may not manipulated", 

the output can see (i included relevant part of page source) in fact show element there, going on? test has 0 problems running on ubuntu.

macbookair:~ hotr$ python ~/desktop/test2.py  ---|||||||||||||||||||||||||| 11.2492170334 seconds |||||||||||||||||||||||||||||||---  <li class="restaurants twolines"> <a href="/restaurants-g150812-playa_del_carmen_yucatan_peninsula.html" data-trk="restaurants_nav" onmousedown="ta.common.header.addclearparam(this);"> <img src="/img2/x.gif" class="typeicon sprite-restaurants_icon" alt="" width="42" height="41"> <span class="typename">restaurants</span> <span class="typeqty">(745)</span> <span class="contentcount">46,865 reviews</span> <img src="/img2/x.gif" class="sprite-nav_arrow" width="8" height="11"> </a> </li> 

wait element to visible:

from selenium import webdriver selenium.webdriver.common.by import selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec   def test(urlx):     br = webdriver.phantomjs('phantomjs')     br.get(urlx)      ta_restaurant_button = webdriverwait(br, 10).until(         ec.visibility_of_element_located((by.css_selector, '.restaurants a'))     )   url = 'http://www.tripadvisor.com/tourism-g150812-playa_del_carmen_yucatan_peninsula-vacations.html' test(url) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -