seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.46k stars 910 forks source link

When the previous step page is not yet fully loaded, the self. open() of the next step has already been run directly #2678

Closed WaterLoran closed 2 months ago

WaterLoran commented 2 months ago

image

  1. After clicking the login button, the homepage needs to be loaded, but due to various reasons, the loading is slow (it is possible that the login was not successful in reality)
  2. When the homepage is not fully loaded, the self. open() function is already used to retrieve a new page Expectation: In the second step, be able to wait for the page to load and complete (by which point you must have successfully logged in) before requesting other URLs Actual situation: Step 2 was not loaded completely, so I directly requested a new URL, and then the URL request failed (possibly due to unsuccessful login) The final solution is to force another one second wait at the first step, so that it can be executed stably Currently, for click operations and assertion text operations, they are relatively stable, but for self. open(), they are not as stable
mdmintz commented 2 months ago

By default, the pageLoadStrategy is set to "normal", but it can be changed via command-line option:

--pls=PLS  # (Set pageLoadStrategy on Chrome: "normal", "eager", or "none".)

Or changed via method arg to Driver() / SB(): (Eg. pls="none")

The pageLoadStrategy determines how long the page waits when it opens a new page. If your script isn't waiting long enough, then you may need to wait for a specific element on a page. Lots of waiting methods for that:

self.wait_for_element_visible(selector)
self.wait_for_element_not_visible(selector)

self.wait_for_element_present(selector)
self.wait_for_element_absent(selector)

Adjust scripts as needed.

WaterLoran commented 2 months ago

Thank you very much for your answer I will optimize my framework well