kaliiiiiiiiii / Selenium-Driverless

undetected Selenium without usage of chromedriver
https://kaliiiiiiiiii.github.io/Selenium-Driverless/
Other
412 stars 52 forks source link

Couldn’t compute element location’s in 30 seconds #238

Closed ahihiyou20 closed 4 weeks ago

ahihiyou20 commented 1 month ago

I opened a prior issue about this with headless being on. I eventually solved it with options.headless instead of adding arguments. However I encountered a new issue with driver.find_element WITHOUT HEADLESS on another computer

Recreating

It’s the exact same as my prior issue, but now without headless

Traceback (most recent call last):
  File "C:\Users\PhamVanKien-KhoaDien\AppData\Local\Programs\Python\Python312\Lib\site-packages\discord\client.py", line 637, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\PhamVanKien-KhoaDien\Videos\OwO\main.py", line 190, in on_ready
    await self.vote_top_gg()
  File "c:\Users\PhamVanKien-KhoaDien\Videos\OwO\main.py", line 995, in vote_top_gg
    await button.click(ensure_clickable = True, scroll_to = True)
  File "C:\Users\PhamVanKien-KhoaDien\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium_driverless\types\webelement.py", line 498, in click
    raise asyncio.TimeoutError(f"Couldn't compute element location within {visible_timeout} seconds")
TimeoutError: Couldn't compute element location within 30 seconds

On my computer it worked perfectly but on another it didn’t even with the latest chrome and same operating system (win10) To clarify, the page didn’t get blocked by cloudflare, it is protected by cloudflare tho. It loaded fine and with the same conditions as my computer did. But it just refuses to find the button

ahihiyou20 commented 1 month ago

The page was fully loaded also

kaliiiiiiiiii commented 1 month ago

The page was fully loaded also

This is usually for example when the page is in a reload-loop.

Closing this bug for now as you haven't provided a minimum reproducible script and without it,. there's no way to fix it for me.

Ofc I'm willing to have a look and re-open it if you provide that.

ahihiyou20 commented 1 month ago

@kaliiiiiiiiii Here is my code

options = webdriver.ChromeOptions()

topgg = "top.gg" # https://top.gg is the page i'm talking about, this is not the actual url that I'm visiting, but it will eventually redirect to this "top.gg" with some cookies (connect.sid for example)
async with webdriver.Chrome(options=options) as driver:
    await driver.get(topgg, wait_load=True, timeout=10)

    await asyncio.sleep(5)

    button = await driver.find_element(
        by=By.XPATH, value='//a[@href="/bot/408785106942164992/vote"]'
    )

    await button.click(ensure_clickable=True, scroll_to=True)

    await asyncio.sleep(10)
    button = await driver.find_element(
        by=By.XPATH, value=".//button[contains(text(),'Vote')]"
    )
    await button.click(ensure_clickable=True)
    await asyncio.sleep(3)

What is a reload-loop actually? And why does this affect only my other PC and not the one I wrote the code? Given the almost identical conditions

kaliiiiiiiiii commented 4 weeks ago

@kaliiiiiiiiii Here is my code

options = webdriver.ChromeOptions()

topgg = "top.gg" # https://top.gg is the page i'm talking about, this is not the actual url that I'm visiting, but it will eventually redirect to this "top.gg" with some cookies (connect.sid for example)
async with webdriver.Chrome(options=options) as driver:
    await driver.get(topgg, wait_load=True, timeout=10)

    await asyncio.sleep(5)

    button = await driver.find_element(
        by=By.XPATH, value='//a[@href="/bot/408785106942164992/vote"]'
    )

    await button.click(ensure_clickable=True, scroll_to=True)

    await asyncio.sleep(10)
    button = await driver.find_element(
        by=By.XPATH, value=".//button[contains(text(),'Vote')]"
    )
    await button.click(ensure_clickable=True)
    await asyncio.sleep(3)

What is a reload-loop actually? And why does this affect only my other PC and not the one I wrote the code? Given the almost identical conditions

  1. Have you confirmed your issue still occurring with that code?
  2. And that dependent on on the device?
kaliiiiiiiiii commented 4 weeks ago

@ahihiyou20 the identifier 408785106942164992 looks to me like it could be dynamic and randomly generated, therefore not found in every case. Maybe try a different selector.

ahihiyou20 commented 4 weeks ago

@kaliiiiiiiiii That number is called an ID, which will never change, if you visit that site you will guarantee to find a button with that specific href Yes, my issue is still occurring with that specific code, I have no idea what’s the issue behind It seems that the issue is dependent on the device since it worked fine to me when it’s not on another computer. With the almost identical site content (it rarely changes). If you want further investigation or debugging, I can provide you with screenshots, videos of the process

ahihiyou20 commented 4 weeks ago

Also what selector should I use? The button I’m looking for have duplicates and contains the same content (text) and css styling. The only thing that varies seem to be the href or that link I’m using. What selector should I use in that case?

ahihiyou20 commented 4 weeks ago

Or is there anyway to use driver.get() and preserve all the cookies since every time I use it Cloudflare just blocks me on the second attempt when I try to go to /bot/408785106942164992/vote, It may seem like its lack of cookies caused the issue and I have to manually click a button to visit that endpoint

kaliiiiiiiiii commented 4 weeks ago

alr let's re-open for now then

ahihiyou20 commented 4 weeks ago

@kaliiiiiiiiii I tried the same code again today and I found it interesting that it worked for the first button, the second button failed still but somehow it worked for the first without any modification. The site is still the same At this point I don’t really know it’s the site’s issue or mine anymore

ahihiyou20 commented 4 weeks ago

Actually I found out that I was using multiple threads with Threading, automating the same site. Which caused the problem, it worked fine with 1 thread So is there anyway to use this library with multiple threads? I was creating driver.Chrome() everytime a thread needs

kaliiiiiiiiii commented 4 weeks ago

Actually I found out that I was using multiple threads with Threading, automating the same site. Which caused the problem, it worked fine with 1 thread So is there anyway to use this library with multiple threads? I was creating driver.Chrome() everytime a thread needs

don't re-use the ChromeOptions