Skip to content

very long wait to open simple webpage via Driver with binary_location #2462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Marwan0 opened this issue Jan 31, 2024 · 3 comments
Closed

very long wait to open simple webpage via Driver with binary_location #2462

Marwan0 opened this issue Jan 31, 2024 · 3 comments
Labels
duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@Marwan0
Copy link

Marwan0 commented Jan 31, 2024

when i use Driver and pass binary_location of ChromeDriver.exe , the script hang and take very very long time to do any action , here is the script i use
`
import os
import sys
import time
from seleniumbase import Driver
from multiprocessing import Pool
import multiprocessing as mp

def get_binary_file_path(relative_path):
"""Get the path to the binary file whether script is run as a script or as an executable."""
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
else:
return os.path.join(os.path.abspath("."), relative_path)

def test_function(I):

driver = Driver(binary_location=r"D:\Python\Prime_checker\chrome.exe",headless=False, undetectable=True)
try:
    driver.get("https://gaming.amazon.com/home")
    time.sleep(3)
    driver.execute_script("window.open('https://www.youtube.com');")
    time.sleep(2)
    driver.switch_to.window(driver.window_handles[0])
    time.sleep(1)
    driver.quit()

except Exception as e:
    driver.quit()
    print(e)

if name == "main":
mp.freeze_support()
for i in range(5):
p = Pool(processes=3)
p.map(test_function, range(3))
p.close()
p.join()
time.sleep(0.5)
`

@mdmintz mdmintz added duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Jan 31, 2024
@mdmintz
Copy link
Member

mdmintz commented Jan 31, 2024

Duplicate of #2006 (comment)

Only pytest multithreading is supported via pytest-xdist.
(In the pytest Syntax Formats, the driver is automatically quit at the end of each test.)

Other multithreading systems such as multiprocessing.Pool are likely to experience issues, such as slowness, poor handling of resources in threads, and other issues.

On top of that, you used the JS window.open() method instead of the built-in UC Mode methods for opening a URL, which may lead to issues. The UC Mode methods will automatically handle tab-switching as needed.

The UC Mode methods:

driver.uc_open(url)
driver.uc_open_with_tab(url)
driver.uc_open_with_reconnect(url, reconnect_time=None)
driver.uc_click(selector)
driver.uc_switch_to_frame(frame)

If you don't need to bypass bot-detection while opening a URL in UC Mode, use: driver.default_get(url), which loads a URL faster because there's no disconnect time between chromedriver and Chrome.

@mdmintz mdmintz closed this as completed Jan 31, 2024
@Marwan0
Copy link
Author

Marwan0 commented Jan 31, 2024 via email

@mdmintz
Copy link
Member

mdmintz commented Jan 31, 2024

The SB() format can also be run with pure Python. (Not just the Driver() format.)

A lot of the example tests that use the BaseCase pytest format have this special line:

BaseCase.main(__name__, __file__)

That triggers pytest when the script is run with pure python. Maybe it's enough for pyinstaller ... maybe not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants