0

I tried to take a unique class_name which only appears after the page is fully loaded but for some other reaseon it apears before it apears on the screen

try:
    WebDriverWait(self.browser, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, 'selo-fechado'))
except:
    pass

what else can I do in order to wait till the page is loaded except for time.sleep(4)?

  • 1
    Does the page use AJAX calls or some Javascript manipulates the DOM? Selenium normally tries to wait by default till the page is loaded, since `driver.get()` is a blocking statement. However AJAX and other JS scripts can still manipulate the DOM which could result in your problem. – DJanssens Aug 11 '15 at 21:35
  • Possibly [this](http://stackoverflow.com/questions/26566799/selenium-python-how-to-wait-until-the-page-is-loaded)? – Brian Aug 11 '15 at 22:33
  • Im afraid the page does use java script, what can I do to come through that? –  Aug 12 '15 at 13:47

2 Answers2

0

I solved the problem by refreshing the website and starting to look on the items and what became visible last

0

Here is what I've found to be the best and most reliable solution:

import sys  
from PyQt4.QtGui import *  
from PyQt4.QtCore import *  
from PyQt4.QtWebKit import *  
from lxml import html 

#Take this class for granted.Just use result of rendering.
class Render(QWebPage):  
  def __init__(self, url):  
    self.app = QApplication(sys.argv)  
    QWebPage.__init__(self)  
    self.loadFinished.connect(self._loadFinished)  
    self.mainFrame().load(QUrl(url))  
    self.app.exec_()  

  def _loadFinished(self, result):  
    self.frame = self.mainFrame()  
    self.app.quit()  

url = 'http://pycoders.com/archive/'  
r = Render(url)  
result = r.frame.toHtml()
#This step is important.Converting QString to Ascii for lxml to process
archive_links = html.fromstring(str(result.toAscii()))
print archive_links

More information here: https://impythonist.wordpress.com/2015/01/06/ultimate-guide-for-scraping-javascript-rendered-web-pages/

Silver Ringvee
  • 5,037
  • 5
  • 28
  • 46