Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ from seleniumbase import SB
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.pokemon.com/us"
sb.activate_cdp_mode(url)
sb.sleep(3.5)
sb.sleep(1.5)
sb.click_if_visible("button#onetrust-accept-btn-handler")
sb.sleep(1.2)
sb.click("a span.icon_pokeball")
Expand Down Expand Up @@ -193,7 +193,7 @@ from seleniumbase import SB
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.hyatt.com/"
sb.activate_cdp_mode(url)
sb.sleep(3.8)
sb.sleep(3.2)
sb.click_if_visible('button[aria-label="Close"]')
sb.sleep(0.1)
sb.click_if_visible("#onetrust-reject-all-handler")
Expand Down Expand Up @@ -282,7 +282,11 @@ from seleniumbase import SB
with SB(uc=True, test=True, ad_block=True) as sb:
url = "https://www.walmart.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.8)
sb.sleep(1.8)
continue_button = 'button:contains("Continue shopping")'
if sb.is_element_visible(continue_button):
sb.cdp.gui_click_element(continue_button)
sb.sleep(0.6)
sb.click('input[aria-label="Search"]')
sb.sleep(1.2)
search = "Settlers of Catan Board Game"
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_cdp_hyatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

url = "https://www.hyatt.com/"
sb = sb_cdp.Chrome(url, locale="en", guest=True)
sb.sleep(4.2)
sb.sleep(3.6)
sb.click_if_visible('button[aria-label="Close"]')
sb.sleep(0.1)
sb.click_if_visible("#onetrust-reject-all-handler")
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_hyatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with SB(uc=True, test=True, locale="en") as sb:
url = "https://www.hyatt.com/"
sb.activate_cdp_mode(url)
sb.sleep(3.8)
sb.sleep(3.2)
sb.click_if_visible('button[aria-label="Close"]')
sb.sleep(0.1)
sb.click_if_visible("#onetrust-reject-all-handler")
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with SB(uc=True, test=True, locale="en", guest=True) as sb:
url = "https://www.pokemon.com/us"
sb.activate_cdp_mode(url)
sb.sleep(3.5)
sb.sleep(1.5)
sb.click_if_visible("button#onetrust-accept-btn-handler")
sb.sleep(1.2)
sb.click("a span.icon_pokeball")
Expand Down
6 changes: 5 additions & 1 deletion examples/cdp_mode/raw_walmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
with SB(uc=True, test=True, ad_block=True) as sb:
url = "https://www.walmart.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.8)
sb.sleep(1.8)
continue_button = 'button:contains("Continue shopping")'
if sb.is_element_visible(continue_button):
sb.cdp.gui_click_element(continue_button)
sb.sleep(0.6)
sb.click('input[aria-label="Search"]')
sb.sleep(1.2)
search = "Settlers of Catan Board Game"
Expand Down
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_xhr_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ async def crawl():

# Change url to something that makes ajax requests
tab = await driver.get("https://learn.microsoft.com/en-us/")
time.sleep(2)
for i in range(20):
await tab.scroll_down(4)
time.sleep(1.5)
for i in range(18):
await tab.scroll_down(3)
time.sleep(0.02)

xhr_responses = await receiveXHR(tab, xhr_requests)
Expand Down
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_xhr_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ async def receiveXHR(page, requests):

# Change url to something that makes ajax requests
sb.cdp.open("https://learn.microsoft.com/en-us/")
time.sleep(2)
for i in range(10):
sb.cdp.scroll_down(8)
time.sleep(1)
for i in range(9):
sb.cdp.scroll_down(6)

loop = sb.cdp.get_event_loop()
xhr_responses = loop.run_until_complete(receiveXHR(tab, xhr_requests))
Expand Down
10 changes: 7 additions & 3 deletions examples/presenter/uc_presentation_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def test_presentation_4(self):
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.pokemon.com/us"
sb.activate_cdp_mode(url)
sb.sleep(3.5)
sb.sleep(1.5)
sb.click_if_visible("button#onetrust-accept-btn-handler")
sb.sleep(1.2)
sb.click("a span.icon_pokeball")
Expand Down Expand Up @@ -515,7 +515,11 @@ def test_presentation_4(self):
with SB(uc=True, test=True, ad_block=True) as sb:
url = "https://www.walmart.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.8)
sb.sleep(1.8)
continue_button = 'button:contains("Continue shopping")'
if sb.is_element_visible(continue_button):
sb.cdp.gui_click_element(continue_button)
sb.sleep(0.6)
sb.click('input[aria-label="Search"]')
sb.sleep(1.2)
search = "Settlers of Catan Board Game"
Expand Down Expand Up @@ -679,7 +683,7 @@ def test_presentation_4(self):
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
url = "https://www.hyatt.com/"
sb.activate_cdp_mode(url)
sb.sleep(3.5)
sb.sleep(3.2)
sb.click_if_visible('button[aria-label="Close"]')
sb.sleep(0.1)
sb.click_if_visible("#onetrust-reject-all-handler")
Expand Down
24 changes: 24 additions & 0 deletions examples/raw_multi_sb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
import threading
from concurrent.futures import ThreadPoolExecutor
from random import randint, seed
from seleniumbase import SB
sys.argv.append("-n") # Tell SeleniumBase to do thread-locking as needed


def launch_driver(url):
seed(len(threading.enumerate())) # Random seed for browser placement
with SB() as sb:
sb.set_window_rect(randint(4, 720), randint(8, 410), 700, 500)
sb.open(url=url)
if sb.is_element_visible("h1"):
sb.highlight("h1", loops=9)
else:
sb.sleep(2.2)


if __name__ == "__main__":
urls = ['https://seleniumbase.io/demo_page' for i in range(4)]
with ThreadPoolExecutor(max_workers=len(urls)) as executor:
for url in urls:
executor.submit(launch_driver, url)
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.44.17"
__version__ = "4.44.18"
16 changes: 6 additions & 10 deletions seleniumbase/console_scripts/sb_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def requests_get_with_retry(url):


def get_cft_known_good_versions():
if hasattr(sb_config, "cft_kgv_json") and sb_config.cft_kgv_json:
if getattr(sb_config, "cft_kgv_json", None):
return sb_config.cft_kgv_json
cft_ngv_url = (
"https://googlechromelabs.github.io/"
Expand All @@ -188,7 +188,7 @@ def get_cft_known_good_versions():


def get_cft_latest_versions_per_milestone():
if hasattr(sb_config, "cft_lvpm_json") and sb_config.cft_lvpm_json:
if getattr(sb_config, "cft_lvpm_json", None):
return sb_config.cft_lvpm_json
cft_lvpm_url = (
"https://googlechromelabs.github.io/"
Expand All @@ -205,7 +205,7 @@ def get_cft_latest_version_from_milestone(milestone):

def get_latest_chromedriver_version(channel="Stable"):
try:
if hasattr(sb_config, "cft_lkgv_json") and sb_config.cft_lkgv_json:
if getattr(sb_config, "cft_lkgv_json", None):
return sb_config.cft_lkgv_json["channels"][channel]["version"]
req = requests_get(
"https://googlechromelabs.github.io/"
Expand Down Expand Up @@ -239,10 +239,7 @@ def get_latest_canary_chromedriver_version():
def log_d(message):
"""If setting sb_config.settings.HIDE_DRIVER_DOWNLOADS to True,
output from driver downloads are logged instead of printed."""
if (
hasattr(sb_config.settings, "HIDE_DRIVER_DOWNLOADS")
and sb_config.settings.HIDE_DRIVER_DOWNLOADS
):
if getattr(sb_config.settings, "HIDE_DRIVER_DOWNLOADS", None):
logging.debug(message)
else:
print(message)
Expand All @@ -251,7 +248,7 @@ def log_d(message):
def main(override=None, intel_for_uc=None, force_uc=None):
if override:
found_proxy = None
if hasattr(sb_config, "proxy_driver") and sb_config.proxy_driver:
if getattr(sb_config, "proxy_driver", None):
if " --proxy=" in " ".join(sys.argv):
for arg in sys.argv:
if arg.startswith("--proxy="):
Expand Down Expand Up @@ -311,8 +308,7 @@ def main(override=None, intel_for_uc=None, force_uc=None):
downloads_folder = DRIVER_DIR
if (
hasattr(sb_config, "settings")
and hasattr(sb_config.settings, "NEW_DRIVER_DIR")
and sb_config.settings.NEW_DRIVER_DIR
and getattr(sb_config.settings, "NEW_DRIVER_DIR", None)
and os.path.exists(sb_config.settings.NEW_DRIVER_DIR)
):
downloads_folder = sb_config.settings.NEW_DRIVER_DIR
Expand Down
Loading