0

For example: from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get("http://stackoverflow.com/")

Like in requests, requests.get returns a status_code. How to know whether to loads the page successfully using selenium?

M1nt_zwy
  • 887
  • 3
  • 9
  • 19
  • Capture the closing html body tag, but it is not enough. You need to set timeout and you may try to capture the end body. Because selenium will wait for the browser to render all the script and plugin, a bug in any part and you will never get the closing body tag. – mootmoot Nov 03 '16 at 10:26
  • Try these http://stackoverflow.com/questions/5868439/wait-for-page-load-in-selenium – pr4bh4sh Nov 04 '16 at 08:26

1 Answers1

0

You can def a function to wait until the body is loaded, and use "ui" from selenium

from selenium import webdriver
from selenium.webdriver.support import ui    

def page_is_loaded(driver):
    return driver.find_element_by_tag_name("body") != None

driver = webdriver.Chrome("C:\chromedriver\chromedriver.exe")
driver.get("www.google.com")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
AntonioRB
  • 149
  • 1
  • 8