#๐ Selenium request: Need help with detecting when a element appears for over 10 minutes
76 messages ยท Page 1 of 1 (latest)
@marble epoch
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.
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
I think your current script doesn't work because it never loads a page
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
So where is that part then?
The element appears multiple times, but for ensuremenet that it reached to the end, I need to assure that the button has appeared over 10 seconds
it isn't related to my request
Because I do access the page
Sure it is. The page in question is definitely related to why it's not working
No this is not true.
there are ways to scroll to the bottom of a page
i found a script a while back that works fine
and are there ways to detect it as like a event and when it occurs print a log
detect what? reaching the bottom?
Yeah
let me find the script rq
I mean let the script knows when u reached the bottom
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:
is it checking the scroller?
what do you mean checking the scroller
Let me try
im not sure why you would need to specifically check the scroll bar widget
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
yes
Okay, let me try it.
So basically the condition of
it will try to scroll, and after it scrolls it sees if it actually moved down,. if not then it breaks
if new_height == last_height:
is this part is the condition that checking the bottom of the page?
is so you could do print("bottom reached") before the break
yeah
or any type of action
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
oh sorry thats my logger name you can remove that
or replace it with print if you want to see it when it starts
Yeah ๐
it still isn't detecting the real bottom
because the page has more content to provide with if u scroll down
@high schooner
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
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?
Maybe the site doesn't want you to detect it
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 && isInfiniteScrollEnabled() && !showViewAllFeaturedItemsButton() && 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
So what is the page?
it is a catalog page
so is there a way to detect when this button appears for over 15 seconds?
Does the page not have a url?
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?
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.