Skip to content

Commit 15a401e

Browse files
committed
Update the documentation
1 parent fbe10bb commit 15a401e

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

examples/cdp_mode/ReadMe.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [<img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32">](https://github.com/seleniumbase/SeleniumBase/) CDP Mode 🐙
44

5-
🐙 <b translate="no">SeleniumBase</b> <b translate="no">CDP Mode</b> (Chrome Devtools Protocol Mode) is a special mode inside of <b><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md" translate="no"><span translate="no">SeleniumBase UC Mode</span></a></b> that lets bots appear human while controlling the browser with the <b translate="no">CDP-Driver</b>. Although regular <span translate="no">UC Mode</span> can't perform <span translate="no">WebDriver</span> actions while the <code>driver</code> is disconnected from the browser, the <span translate="no">CDP-Driver</span> can still perform actions (while maintaining its cover).
5+
🐙 <b translate="no">SeleniumBase</b> <b translate="no">CDP Mode</b> (Chrome Devtools Protocol Mode) is a special mode inside of <b><a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/uc_mode.md" translate="no"><span translate="no">SeleniumBase UC Mode</span></a></b> that lets bots appear human while controlling the browser with the <b translate="no">CDP-Driver</b>. Although regular <span translate="no">UC Mode</span> can't perform <span translate="no">WebDriver</span> actions while the <code>driver</code> is disconnected from the browser, the <span translate="no">CDP-Driver</span> can still perform actions while maintaining its cover. (For Python 3.11 or newer!)
66

77
👤 <b translate="no">UC Mode</b> avoids bot-detection by first disconnecting WebDriver from the browser at strategic times, calling special <code>PyAutoGUI</code> methods to bypass CAPTCHAs (as needed), and finally reconnecting the <code>driver</code> afterwards so that WebDriver actions can be performed again. Although this approach works for bypassing simple CAPTCHAs, more flexibility is needed for bypassing bot-detection on websites with advanced protection. (That's where <b translate="no">CDP Mode</b> comes in.)
88

@@ -74,15 +74,15 @@ from seleniumbase import SB
7474
with SB(uc=True, test=True, locale_code="en") as sb:
7575
url = "https://www.pokemon.com/us"
7676
sb.activate_cdp_mode(url)
77-
sb.sleep(1.5)
77+
sb.sleep(3)
7878
sb.cdp.click_if_visible("button#onetrust-reject-all-handler")
79-
sb.sleep(0.5)
79+
sb.sleep(1)
8080
sb.cdp.click('a[href="https://www.pokemon.com/us/pokedex/"]')
8181
sb.sleep(1)
8282
sb.cdp.click('b:contains("Show Advanced Search")')
8383
sb.sleep(1)
8484
sb.cdp.click('span[data-type="type"][data-value="electric"]')
85-
sb.sleep(0.5)
85+
sb.sleep(1)
8686
sb.cdp.click("a#advSearch")
8787
sb.sleep(1)
8888
sb.cdp.click('img[src*="img/pokedex/detail/025.png"]')
@@ -130,13 +130,13 @@ from seleniumbase import SB
130130
with SB(uc=True, test=True, locale_code="en") as sb:
131131
url = "https://www.hyatt.com/"
132132
sb.activate_cdp_mode(url)
133-
sb.sleep(1.5)
133+
sb.sleep(2)
134134
sb.cdp.click_if_visible('button[aria-label="Close"]')
135-
sb.sleep(0.5)
135+
sb.sleep(1)
136136
sb.cdp.click('span:contains("Explore")')
137137
sb.sleep(1)
138138
sb.cdp.click('a:contains("Hotels & Resorts")')
139-
sb.sleep(2.5)
139+
sb.sleep(3)
140140
location = "Anaheim, CA, USA"
141141
sb.cdp.press_keys("input#searchbox", location)
142142
sb.sleep(1)
@@ -145,7 +145,7 @@ with SB(uc=True, test=True, locale_code="en") as sb:
145145
sb.cdp.click('div.hotel-card-footer button')
146146
sb.sleep(1)
147147
sb.cdp.click('button[data-locator="find-hotels"]')
148-
sb.sleep(4)
148+
sb.sleep(5)
149149
hotel_names = sb.cdp.select_all(
150150
'div[data-booking-status="BOOKABLE"] [class*="HotelCard_header"]'
151151
)
@@ -177,20 +177,20 @@ from seleniumbase import SB
177177
with SB(uc=True, test=True, locale_code="en") as sb:
178178
url = "https://www.bestwestern.com/en_US.html"
179179
sb.activate_cdp_mode(url)
180-
sb.sleep(1.5)
180+
sb.sleep(2.5)
181181
sb.cdp.click_if_visible("div.onetrust-close-btn-handler")
182-
sb.sleep(0.5)
182+
sb.sleep(1)
183183
sb.cdp.click("input#destination-input")
184-
sb.sleep(1.5)
184+
sb.sleep(2)
185185
location = "Palm Springs, CA, USA"
186186
sb.cdp.press_keys("input#destination-input", location)
187-
sb.sleep(0.6)
187+
sb.sleep(1)
188188
sb.cdp.click("ul#google-suggestions li")
189-
sb.sleep(0.6)
189+
sb.sleep(1)
190190
sb.cdp.click("button#btn-modify-stay-update")
191-
sb.sleep(1.5)
192-
sb.cdp.click("label#available-label")
193191
sb.sleep(4)
192+
sb.cdp.click("label#available-label")
193+
sb.sleep(2.5)
194194
print("Best Western Hotels in %s:" % location)
195195
summary_details = sb.cdp.get_text("#summary-details-column")
196196
dates = summary_details.split("ROOM")[0].split("DATES")[-1].strip()
@@ -288,6 +288,7 @@ sb.cdp.get_document()
288288
sb.cdp.get_flattened_document()
289289
sb.cdp.get_element_attributes(selector)
290290
sb.cdp.get_element_html(selector)
291+
sb.cdp.set_locale(locale)
291292
sb.cdp.set_attributes(selector, attribute, value)
292293
sb.cdp.internalize_links()
293294
sb.cdp.is_element_present(selector)

help_docs/method_summary.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ self.save_page_source(name, folder=None)
349349

350350
self.save_cookies(name="cookies.txt")
351351

352-
self.load_cookies(name="cookies.txt")
352+
self.load_cookies(name="cookies.txt", expiry=False)
353353

354354
self.delete_all_cookies()
355355
# Duplicates: self.clear_all_cookies()
@@ -362,9 +362,9 @@ self.get_cookie(name)
362362

363363
self.get_cookies()
364364

365-
self.add_cookie(cookie_dict)
365+
self.add_cookie(cookie_dict, expiry=False)
366366

367-
self.add_cookies(cookies)
367+
self.add_cookies(cookies, expiry=False)
368368

369369
self.wait_for_ready_state_complete(timeout=None)
370370

0 commit comments

Comments
 (0)