Wait page for python Selenium

Asked

Viewed 3,380 times

2

I created a program to log in to 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 sometimes it takes 50 seconds and error and has hours that takes 20 seconds and is long idle, I tried the webdriverwait but it didn’t work, would have any solution to give me? This code contains 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()
  • That one WebDriverWait that you put is waiting at most 10 seconds - if you said the minimum is 20, maybe you’re waiting a little? Increase to 100 seconds and see if it improves.

  • But that’s the problem, I don’t want you to wait a lot of time, I want him to automate, outside that this code is giving error

  • So - the purpose of WebDriverWait is to wait until the element appears. You have to put a time well above what you need, because it will wait at most that time - the idea is that if the element is located it stops waiting immediately, So you have to give him enough time to be located. The code must be failing because you put a very short time, after 10 seconds the element has not yet appeared.

  • Yes, thank you, it worked now, I had misunderstood

1 answer

1


you can use Webdriverwait together with

EC.presence_of_element_located()

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

time.Sleep(team)

Here’s an example I use in my Selenium tests.

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())

Voce can put to show in the terminal whether the element is visible or not assism you can see better what is happening

  • 1

    Perfect, it worked, thank you

  • Just don’t forget to check that my answer is useful :D ...

  • I checked already, thanks, I even have, but they said that it is not possible to change the name of a pdf in python

Browser other questions tagged

You are not signed in. Login or sign up in order to post.