Wait page load for selenium in python

1

I created a program to log into the site, but it loads very slowly when it opens, and for that I need to put sleep (40), which waits 40 seconds to open, but has times that takes 50 seconds and the error and has hours it takes 20 seconds and it is very idle time, I tried the webdriverwait but it did not work, would you have some solution to give me? This code gives the following error: selenium.common.exceptions.TimeoutException: Message:

driver = webdriver.Chrome('C:\scrapy\chromedriver', chrome_options=chrome_options)
driver.get('site')
#sleep(25)
element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, "elementEmail"))
    )
email = driver.find_element_by_xpath('//*[@translate="@APP-COMMON-EMAIL"]')
email.click()
    
asked by anonymous 22.10.2018 / 19:11

1 answer

1

You can use WebDriverWait along with

  

EC.presence_of_element_located ()

It will wait a set time or until the element is visible, however depending on the case you still have to put the system to wait in this case you use to be able to stop the script by the time set.

  

time.sleep (time)

Here is an example that I use in my tests with selenium.

from selenium.webdriver.support import expected_conditions as EC
import time as time
element = WebDriverWait(driver, 120).until(EC.presence_of_element_located((By.NAME, 'tag')))
time.sleep(5)
print(element.is_displayed())

You can put it to show in the terminal if the element is visible or not assism you can see better what is happening

    
22.10.2018 / 19:32