#๐Ÿ”’ Selenium request: Need help with detecting when a element appears for over 10 minutes

76 messages ยท Page 1 of 1 (latest)

polar brookBOT
#

@marble epoch

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

marble epoch
#

Selenium request: Need help with detecting when a element appears for over 10 seconds

#

current script:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import time
import re

    scroll_to_top_button = driver.find_elements(By.CSS_SELECTOR, "button.scroll-to-top.icon-back-to-top")
    if scroll_to_top_button:

        try:
            scroll_to_top_button = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((By.CSS_SELECTOR, "button.scroll-to-top.icon-back-to-top"))
            )
            print("You reached to the end of the page")
        except:
            print("Scroll-to-top button not found within 10 seconds")
#

Please help

simple fulcrum
#

I think your current script doesn't work because it never loads a page

marble epoch
#

I mean this is a small part of my script

#

This isn't my fully script, I've already did the rest myself,

like for example, the driver.get(url) I did this part, and it is accessing the page

simple fulcrum
#

So where is that part then?

marble epoch
marble epoch
#

Because I do access the page

simple fulcrum
#

Sure it is. The page in question is definitely related to why it's not working

marble epoch
#

No this is not true.

high schooner
#

there are ways to scroll to the bottom of a page

marble epoch
#

The reason is I can fetch elements from the page

#

and it did work correctly

high schooner
#

i found a script a while back that works fine

marble epoch
high schooner
#

detect what? reaching the bottom?

marble epoch
#

Yeah

high schooner
#

let me find the script rq

marble epoch
#

I mean let the script knows when u reached the bottom

high schooner
#
    def scroll_down(driver) -> None:
        """Scrolls page until the end is reached

        :param driver: the driver to execute the script on
        :type driver: object
        :returns: None
        """
        c_log.debug("Scrolling")
        last_height = driver.execute_script("return document.body.scrollHeight")

        while True:
            driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

            WebDriverWait(driver, random.randrange(0, 2))

            new_height = driver.execute_script("return document.body.scrollHeight")

            if new_height == last_height:
                break

            last_height = new_height
#

so you could put something under the if new_height == last_height:

marble epoch
#

is it checking the scroller?

high schooner
#

what do you mean checking the scroller

marble epoch
#

I mean the scroller layout

high schooner
#

it gets the height of the page

#

it should work for what you need

marble epoch
#

Let me try

high schooner
#

im not sure why you would need to specifically check the scroll bar widget

marble epoch
#

But what if u scroll down and it loads more contents of the page

#

will it detect the actual page down where scrolling is unable

high schooner
#

yes

marble epoch
#

Okay, let me try it.

marble epoch
high schooner
#

it will try to scroll, and after it scrolls it sees if it actually moved down,. if not then it breaks

marble epoch
#
            if new_height == last_height:

is this part is the condition that checking the bottom of the page?

high schooner
#

is so you could do print("bottom reached") before the break

marble epoch
#

yeah

high schooner
#

or any type of action

marble epoch
#

I was planning to do that

#

Okay, let me test it.

#

it looks like c_log is undefined

#

could you tell me what that is?

#

@high schooner

high schooner
#

oh sorry thats my logger name you can remove that

#

or replace it with print if you want to see it when it starts

marble epoch
#

Yeah ๐Ÿ‘

#

it still isn't detecting the real bottom

#

because the page has more content to provide with if u scroll down

#

@high schooner

simple fulcrum
#

It's one of those like frames within a page so the bottom really isn't the bottom

#

And/or it's loading/caching more as you scroll down

#

So the bottom at any given time is just the cached bottom

marble epoch
#

but I mean, sometimes there is a real bottom, which is the actually last bottom

#

if there are no more results

#

but there isn't any lael or anything that represents that

#

@simple fulcrum @high schooner is there any way to detect that?

simple fulcrum
#

Maybe the site doesn't want you to detect it

marble epoch
#

I mean there is a way to detect it

#
<button class="scroll-to-top icon-back-to-top" ng-click="returnToTop()" ng-show="!layout.loading &amp;&amp; isInfiniteScrollEnabled() &amp;&amp; !showViewAllFeaturedItemsButton() &amp;&amp; showReturnToTop()"> </button>

if I can check if this button appears for over 15 seconds,
then it should detect that the page has reached to the end

#

@simple fulcrum @high schooner

simple fulcrum
#

So what is the page?

marble epoch
#

it is a catalog page

#

so is there a way to detect when this button appears for over 15 seconds?

simple fulcrum
#

Does the page not have a url?

marble epoch
#

it does

#

Here is it

#

and the real bottom looks like this

#

So if I could when this button appears for over 15 seconds then I will be able to detect the bottom

#

@simple fulcrum @high schooner Do you guys know how to code a script that recognize it only ifi t appeared for over 15 seocnds?

polar brookBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.