Skip to content

Commit 320b125

Browse files
committed
Update CDP Mode
1 parent b7c49e1 commit 320b125

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ def uc_open_with_cdp_mode(driver, url=None):
658658
cdp.get_window = CDPM.get_window
659659
cdp.get_element_attributes = CDPM.get_element_attributes
660660
cdp.get_element_attribute = CDPM.get_element_attribute
661+
cdp.get_attribute = CDPM.get_attribute
661662
cdp.get_element_html = CDPM.get_element_html
662663
cdp.get_element_rect = CDPM.get_element_rect
663664
cdp.get_element_size = CDPM.get_element_size
@@ -2321,7 +2322,6 @@ def _set_chrome_options(
23212322
chrome_options.add_argument("--disable-ipc-flooding-protection")
23222323
chrome_options.add_argument("--disable-password-generation")
23232324
chrome_options.add_argument("--disable-domain-reliability")
2324-
chrome_options.add_argument("--disable-component-update")
23252325
chrome_options.add_argument("--disable-breakpad")
23262326
included_disabled_features = []
23272327
included_disabled_features.append("OptimizationHints")
@@ -4071,7 +4071,6 @@ def get_local_driver(
40714071
edge_options.add_argument("--disable-ipc-flooding-protection")
40724072
edge_options.add_argument("--disable-password-generation")
40734073
edge_options.add_argument("--disable-domain-reliability")
4074-
edge_options.add_argument("--disable-component-update")
40754074
edge_options.add_argument("--disable-breakpad")
40764075
included_disabled_features = []
40774076
included_disabled_features.append("OptimizationHints")

seleniumbase/core/sb_cdp.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ def __add_sync_methods(self, element):
8383
element.get_position = lambda: self.__get_position(element)
8484
element.get_html = lambda: self.__get_html(element)
8585
element.get_js_attributes = lambda: self.__get_js_attributes(element)
86+
element.get_attribute = (
87+
lambda attribute: self.__get_attribute(element, attribute)
88+
)
8689
return element
8790

8891
def get(self, url):
@@ -440,6 +443,12 @@ def __get_js_attributes(self, element):
440443
self.loop.run_until_complete(element.get_js_attributes_async())
441444
)
442445

446+
def __get_attribute(self, element, attribute):
447+
try:
448+
return element.get_js_attributes()[attribute]
449+
except Exception:
450+
return None
451+
443452
def __get_x_scroll_offset(self):
444453
x_scroll_offset = self.loop.run_until_complete(
445454
self.page.evaluate("window.pageXOffset")
@@ -1013,8 +1022,10 @@ def get_element_attributes(self, selector):
10131022
)
10141023

10151024
def get_element_attribute(self, selector, attribute):
1016-
attributes = self.get_element_attributes(selector)
1017-
return attributes[attribute]
1025+
return self.get_element_attributes(selector)[attribute]
1026+
1027+
def get_attribute(self, selector, attribute):
1028+
return self.find_element(selector).get_attribute(attribute)
10181029

10191030
def get_element_html(self, selector):
10201031
selector = self.__convert_to_css_if_xpath(selector)
@@ -1774,31 +1785,26 @@ def scroll_to_y(self, y):
17741785
with suppress(Exception):
17751786
self.loop.run_until_complete(self.page.evaluate(js_code))
17761787
self.loop.run_until_complete(self.page.wait())
1777-
self.__add_light_pause()
17781788

17791789
def scroll_to_top(self):
17801790
js_code = "window.scrollTo(0, 0);"
17811791
with suppress(Exception):
17821792
self.loop.run_until_complete(self.page.evaluate(js_code))
17831793
self.loop.run_until_complete(self.page.wait())
1784-
self.__add_light_pause()
17851794

17861795
def scroll_to_bottom(self):
17871796
js_code = "window.scrollTo(0, 10000);"
17881797
with suppress(Exception):
17891798
self.loop.run_until_complete(self.page.evaluate(js_code))
17901799
self.loop.run_until_complete(self.page.wait())
1791-
self.__add_light_pause()
17921800

17931801
def scroll_up(self, amount=25):
17941802
self.loop.run_until_complete(self.page.scroll_up(amount))
17951803
self.loop.run_until_complete(self.page.wait())
1796-
self.__add_light_pause()
17971804

17981805
def scroll_down(self, amount=25):
17991806
self.loop.run_until_complete(self.page.scroll_down(amount))
18001807
self.loop.run_until_complete(self.page.wait())
1801-
self.__add_light_pause()
18021808

18031809
def save_screenshot(self, name, folder=None, selector=None):
18041810
filename = name

seleniumbase/fixtures/base_case.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6051,10 +6051,8 @@ def highlight(
60516051
scroll - the option to scroll to the element first (Default: True)
60526052
timeout - the time to wait for the element to appear """
60536053
self.__check_scope()
6054-
if self.__is_cdp_swap_needed() and ":contains(" not in selector:
6055-
self.cdp.highlight(selector)
6056-
return
6057-
self._check_browser()
6054+
if not self.__is_cdp_swap_needed():
6055+
self._check_browser()
60586056
self.__skip_if_esc()
60596057
if isinstance(selector, WebElement):
60606058
self.__highlight_element(selector, loops=loops, scroll=scroll)
@@ -13860,7 +13858,8 @@ def __slow_scroll_to_element(self, element):
1386013858
js_utils.scroll_to_element(self.driver, element)
1386113859

1386213860
def __highlight_with_js(self, selector, loops, o_bs):
13863-
self.wait_for_ready_state_complete()
13861+
if not self.__is_cdp_swap_needed():
13862+
self.wait_for_ready_state_complete()
1386413863
js_utils.highlight_with_js(self.driver, selector, loops, o_bs)
1386513864

1386613865
def __highlight_element_with_js(self, element, loops, o_bs):

seleniumbase/undetected/cdp_driver/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def __init__(
125125
"--deny-permission-prompts",
126126
"--disable-infobars",
127127
"--disable-breakpad",
128-
"--disable-component-update",
129128
"--disable-prompt-on-repost",
130129
"--disable-password-generation",
131130
"--disable-ipc-flooding-protection",

seleniumbase/undetected/cdp_driver/element.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22
import asyncio
3-
import json
43
import logging
54
import pathlib
65
import secrets
@@ -387,18 +386,16 @@ async def click_async(self):
387386

388387
async def get_js_attributes_async(self):
389388
return ContraDict(
390-
json.loads(
391-
await self.apply(
392-
"""
393-
function (e) {
394-
let o = {}
395-
for(let k in e){
396-
o[k] = e[k]
389+
await self.apply(
390+
"""
391+
function (e) {
392+
let o = {}
393+
for(let k in e){
394+
o[k] = e[k]
395+
}
396+
return o
397397
}
398-
return JSON.stringify(o)
399-
}
400-
"""
401-
)
398+
"""
402399
)
403400
)
404401

0 commit comments

Comments
 (0)