seleniumUts 1.0.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/PKG-INFO +1 -1
- seleniumuts-1.1.0/seleniumUts/__init__.py +315 -0
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/seleniumUts.egg-info/PKG-INFO +1 -1
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/setup.py +1 -1
- seleniumuts-1.0.0/seleniumUts/__init__.py +0 -184
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/README.md +0 -0
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/seleniumUts.egg-info/SOURCES.txt +0 -0
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/seleniumUts.egg-info/dependency_links.txt +0 -0
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/seleniumUts.egg-info/requires.txt +0 -0
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/seleniumUts.egg-info/top_level.txt +0 -0
- {seleniumuts-1.0.0 → seleniumuts-1.1.0}/setup.cfg +0 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
2
|
+
from selenium.webdriver.common.by import By
|
|
3
|
+
import undetected_chromedriver as uc
|
|
4
|
+
from selenium import webdriver
|
|
5
|
+
from selenium.webdriver.remote.webelement import WebElement
|
|
6
|
+
from selenium.webdriver.support.ui import Select, WebDriverWait
|
|
7
|
+
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
|
|
8
|
+
import time
|
|
9
|
+
|
|
10
|
+
CAPABILITIES = {
|
|
11
|
+
"browserName": "chrome",
|
|
12
|
+
"version": "110.0",
|
|
13
|
+
"name": "default",
|
|
14
|
+
"enableVNC" : True,
|
|
15
|
+
"enableVideo": False,
|
|
16
|
+
"sessionTimeout": "30m"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
DEFAULT_OPTIONS = [
|
|
20
|
+
#"--disable-web-security",
|
|
21
|
+
"--verbose",
|
|
22
|
+
#"--no-sandbox",
|
|
23
|
+
"--disable-infobars",
|
|
24
|
+
"--disable-extensions",
|
|
25
|
+
"--disable-notifications",
|
|
26
|
+
"--disable-gpu",
|
|
27
|
+
'--start-maximized',
|
|
28
|
+
'--disable-blink-features=AutomationControlled',
|
|
29
|
+
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CWebElement(WebElement):
|
|
34
|
+
def __init__(self, *args, **kwargs):
|
|
35
|
+
super().__init__(*args, **kwargs)
|
|
36
|
+
|
|
37
|
+
def delayed_send(self, word, delay=0.5):
|
|
38
|
+
"""
|
|
39
|
+
Desc:
|
|
40
|
+
Send keys to the element with a delay between each character.\n
|
|
41
|
+
Args:
|
|
42
|
+
- ``word`` - The string to be sent to the element.
|
|
43
|
+
- ``delay`` - The delay between each character in seconds.
|
|
44
|
+
Default: 0.5 seconds.
|
|
45
|
+
"""
|
|
46
|
+
for c in word:
|
|
47
|
+
self.send_keys(c)
|
|
48
|
+
time.sleep(delay)
|
|
49
|
+
|
|
50
|
+
def focus(self):
|
|
51
|
+
"""Foca no elemento"""
|
|
52
|
+
self.parent.execute_script("arguments[0].scrollIntoView(true);", self)
|
|
53
|
+
time.sleep(0.5)
|
|
54
|
+
self.parent.execute_script("arguments[0].focus();", self)
|
|
55
|
+
return self
|
|
56
|
+
|
|
57
|
+
def select_by_text(self, text):
|
|
58
|
+
"""Seleciona item em dropdown pelo texto visível"""
|
|
59
|
+
Select(self).select_by_visible_text(text)
|
|
60
|
+
return self
|
|
61
|
+
|
|
62
|
+
def select_by_value(self, value):
|
|
63
|
+
"""Seleciona item em dropdown pelo valor"""
|
|
64
|
+
Select(self).select_by_value(value)
|
|
65
|
+
return self
|
|
66
|
+
|
|
67
|
+
def click_js(self):
|
|
68
|
+
"""Clica no elemento usando JavaScript (evita toggle indesejado)"""
|
|
69
|
+
self.driver.execute_script("arguments[0].click();", self)
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class CustomRemoteDriver(RemoteWebDriver):
|
|
74
|
+
def create_web_element(self, element_id):
|
|
75
|
+
return CWebElement(self, element_id)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class SeleniumUts:
|
|
79
|
+
driver = None
|
|
80
|
+
|
|
81
|
+
def close(self):
|
|
82
|
+
"""
|
|
83
|
+
Desc:
|
|
84
|
+
Close the browser.\n
|
|
85
|
+
Args: None
|
|
86
|
+
"""
|
|
87
|
+
if self.driver:
|
|
88
|
+
self.driver.quit()
|
|
89
|
+
self.driver = None
|
|
90
|
+
|
|
91
|
+
def wait_loads(self, tm=5):
|
|
92
|
+
wait = WebDriverWait(self.driver, 60)
|
|
93
|
+
wt = lambda a: self.driver.execute_script("return document.readyState==\"complete\";")
|
|
94
|
+
wait.until(wt)
|
|
95
|
+
time.sleep(tm)
|
|
96
|
+
|
|
97
|
+
def open_page(self,page):
|
|
98
|
+
"""
|
|
99
|
+
Desc:
|
|
100
|
+
Open a page in the browser.\n
|
|
101
|
+
and wait for it to load.\n
|
|
102
|
+
Args:
|
|
103
|
+
- ``page`` - The URL of the page to be opened.
|
|
104
|
+
Returns:
|
|
105
|
+
- The WebDriver instance.
|
|
106
|
+
"""
|
|
107
|
+
self.driver.get(page)
|
|
108
|
+
self.driver.implicitly_wait(2)
|
|
109
|
+
self.wait_loads()
|
|
110
|
+
|
|
111
|
+
return self.driver
|
|
112
|
+
|
|
113
|
+
def find_xpath(self, xpath, time=20):
|
|
114
|
+
"""Retorna elemento pelo XPath"""
|
|
115
|
+
return self.wait_xpath(xpath, time=time)
|
|
116
|
+
|
|
117
|
+
def find_css(self, selector, time=20):
|
|
118
|
+
"""Retorna elemento pelo CSS"""
|
|
119
|
+
return self.wait_css(selector, time=time)
|
|
120
|
+
|
|
121
|
+
def wait_xpath(self,path,time=20,throw=True):
|
|
122
|
+
"""
|
|
123
|
+
Desc:
|
|
124
|
+
Wait for an element to be visible using its XPATH.\n
|
|
125
|
+
Args:
|
|
126
|
+
- ``path`` - The XPATH of the element to be waited for.
|
|
127
|
+
- ``time`` - Maximum time to wait for the element in seconds. Default is 20 seconds.
|
|
128
|
+
- ``throw`` - If True, raises an exception if the element is not found within the time limit.
|
|
129
|
+
Returns:
|
|
130
|
+
- The WebElement if found, otherwise None.
|
|
131
|
+
"""
|
|
132
|
+
try:
|
|
133
|
+
element = WebDriverWait(self.driver, time).until(
|
|
134
|
+
EC.visibility_of_element_located((By.XPATH, path)))
|
|
135
|
+
return element
|
|
136
|
+
except:
|
|
137
|
+
if throw: raise
|
|
138
|
+
return None
|
|
139
|
+
|
|
140
|
+
def wait_css(self, selector, time=20, throw=True):
|
|
141
|
+
try:
|
|
142
|
+
element = WebDriverWait(self.driver, time).until(
|
|
143
|
+
EC.visibility_of_element_located((By.CSS_SELECTOR, selector)) )
|
|
144
|
+
return element
|
|
145
|
+
except:
|
|
146
|
+
if throw: raise
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
def wait_id(self, element_id, time=10,throw=True):
|
|
150
|
+
"""Seleciona item em dropdown pelo texto visível"""
|
|
151
|
+
try:
|
|
152
|
+
elem = WebDriverWait(self.driver, time).until(
|
|
153
|
+
EC.presence_of_element_located((By.ID, element_id))
|
|
154
|
+
)
|
|
155
|
+
return elem
|
|
156
|
+
except:
|
|
157
|
+
if throw: raise
|
|
158
|
+
return None
|
|
159
|
+
|
|
160
|
+
def scroll_end(self):
|
|
161
|
+
"""
|
|
162
|
+
Desc:
|
|
163
|
+
Scroll to the end of the page.\n
|
|
164
|
+
Args: None
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
get_pos = lambda:self.driver.execute_script("return document.documentElement.scrollTop")
|
|
168
|
+
|
|
169
|
+
while True:
|
|
170
|
+
atual_pos = get_pos()
|
|
171
|
+
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
|
172
|
+
time.sleep(2)
|
|
173
|
+
future_pos = get_pos()
|
|
174
|
+
if future_pos == atual_pos:
|
|
175
|
+
break
|
|
176
|
+
|
|
177
|
+
def accept_alert(self, time=10):
|
|
178
|
+
"""Aguarda e aceita alert do navegador"""
|
|
179
|
+
WebDriverWait(self.driver, time).until(EC.alert_is_present())
|
|
180
|
+
alert = self.driver.switch_to.alert
|
|
181
|
+
txt = alert.text
|
|
182
|
+
alert.accept()
|
|
183
|
+
return txt
|
|
184
|
+
|
|
185
|
+
def switch_to_new_window(self):
|
|
186
|
+
"""Troca para a última janela aberta"""
|
|
187
|
+
windows = self.driver.window_handles
|
|
188
|
+
self.driver.switch_to.window(windows[-1])
|
|
189
|
+
return windows
|
|
190
|
+
|
|
191
|
+
def element_exists_xpath(self, xpath, time=5):
|
|
192
|
+
"""Verifica se um elemento existe pelo XPATH"""
|
|
193
|
+
try:
|
|
194
|
+
WebDriverWait(self.driver, time).until(
|
|
195
|
+
EC.visibility_of_element_located((By.XPATH, xpath))
|
|
196
|
+
)
|
|
197
|
+
return True
|
|
198
|
+
except:
|
|
199
|
+
return False
|
|
200
|
+
|
|
201
|
+
def element_exists_css(self, selector, time=5):
|
|
202
|
+
"""Verifica se um elemento existe por CSS"""
|
|
203
|
+
try:
|
|
204
|
+
WebDriverWait(self.driver, time).until(
|
|
205
|
+
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
|
|
206
|
+
)
|
|
207
|
+
return True
|
|
208
|
+
except:
|
|
209
|
+
return False
|
|
210
|
+
|
|
211
|
+
def element_exists(self, by, value, time=5):
|
|
212
|
+
try:
|
|
213
|
+
WebDriverWait(self.driver, time).until(
|
|
214
|
+
EC.presence_of_element_located((by, value))
|
|
215
|
+
)
|
|
216
|
+
return True
|
|
217
|
+
except:
|
|
218
|
+
return False
|
|
219
|
+
|
|
220
|
+
def startRemoteSelenium(
|
|
221
|
+
self,
|
|
222
|
+
host,
|
|
223
|
+
name="default",
|
|
224
|
+
cust_opt = [],
|
|
225
|
+
remove_default_options=False,
|
|
226
|
+
download_path=None,
|
|
227
|
+
selenoid_browser=("chrome","128.0")
|
|
228
|
+
) -> webdriver:
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
#===================== OPTIONS ==============================
|
|
232
|
+
options = []
|
|
233
|
+
if not remove_default_options:
|
|
234
|
+
options = DEFAULT_OPTIONS
|
|
235
|
+
options += cust_opt
|
|
236
|
+
|
|
237
|
+
web_options = webdriver.ChromeOptions()
|
|
238
|
+
for op in options:
|
|
239
|
+
web_options.add_argument(op)
|
|
240
|
+
|
|
241
|
+
web_options.headless = False
|
|
242
|
+
|
|
243
|
+
#==================== PREFERENCES ===========================
|
|
244
|
+
prefs = {
|
|
245
|
+
"download.default_directory" : download_path,
|
|
246
|
+
"download.directory_upgrade" : True,
|
|
247
|
+
"download.prompt_for_download" : False,
|
|
248
|
+
"safebrowsing.enabled" : False,
|
|
249
|
+
"credentials_enable_service" : False,
|
|
250
|
+
"profile.password_manager_enabled" : False,
|
|
251
|
+
"autofill.profile_enabled" : False,
|
|
252
|
+
"plugins.always_open_pdf_externally" : True,
|
|
253
|
+
"profile.password_manager_leak_detection": False,
|
|
254
|
+
}
|
|
255
|
+
web_options.add_experimental_option("prefs", prefs)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
#================== START BROWSER ===========================
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
web_options.add_experimental_option("useAutomationExtension", False)
|
|
262
|
+
web_options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
|
263
|
+
|
|
264
|
+
CAPABILITIES["name"] = name
|
|
265
|
+
CAPABILITIES["browserName"] = selenoid_browser[0]
|
|
266
|
+
CAPABILITIES["version"] = selenoid_browser[1]
|
|
267
|
+
web_options.set_capability(name="selenoid:options", value=CAPABILITIES)
|
|
268
|
+
web_options.set_capability(name="browserName", value=CAPABILITIES["browserName"])
|
|
269
|
+
|
|
270
|
+
self.driver = CustomRemoteDriver(command_executor=host, options=web_options)
|
|
271
|
+
self.driver.maximize_window()
|
|
272
|
+
self.driver.implicitly_wait(10)
|
|
273
|
+
|
|
274
|
+
return self.driver
|
|
275
|
+
|
|
276
|
+
def startUC(
|
|
277
|
+
self,
|
|
278
|
+
version_main: int = 142,
|
|
279
|
+
enable_cdp_events: bool = True,
|
|
280
|
+
download_path: str = None,
|
|
281
|
+
custom_prefs: dict = {},
|
|
282
|
+
custom_args: list = []
|
|
283
|
+
):
|
|
284
|
+
options = uc.ChromeOptions()
|
|
285
|
+
|
|
286
|
+
# PREFS padrão
|
|
287
|
+
prefs = {
|
|
288
|
+
"credentials_enable_service": False,
|
|
289
|
+
"profile.password_manager_enabled": False,
|
|
290
|
+
"profile.password_manager_leak_detection": False,
|
|
291
|
+
"download.default_directory": download_path,
|
|
292
|
+
}
|
|
293
|
+
prefs.update(custom_prefs)
|
|
294
|
+
options.add_experimental_option("prefs", prefs)
|
|
295
|
+
|
|
296
|
+
# ARGUMENTOS padrão
|
|
297
|
+
default_args = DEFAULT_OPTIONS.copy()
|
|
298
|
+
default_args.extend(custom_args)
|
|
299
|
+
|
|
300
|
+
for arg in default_args:
|
|
301
|
+
options.add_argument(arg)
|
|
302
|
+
|
|
303
|
+
# REMOVIDO: options.add_experimental_option("detach", True)
|
|
304
|
+
# Isso QUEBRA o UC e gera o erro que você recebeu.
|
|
305
|
+
|
|
306
|
+
# start UC
|
|
307
|
+
driver = uc.Chrome(
|
|
308
|
+
options=options,
|
|
309
|
+
enable_cdp_events=enable_cdp_events,
|
|
310
|
+
version_main=version_main,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
self.driver = driver
|
|
314
|
+
driver.implicitly_wait(10)
|
|
315
|
+
return driver
|
|
@@ -10,7 +10,7 @@ classifiers = [
|
|
|
10
10
|
|
|
11
11
|
setup(
|
|
12
12
|
name = 'seleniumUts',
|
|
13
|
-
version = '1.
|
|
13
|
+
version = '1.1.0',
|
|
14
14
|
packages = find_packages(),
|
|
15
15
|
long_description = open('README.md').read() + '\n\n' + open('CHANGELOG.txt').read(),
|
|
16
16
|
long_description_content_type = 'text/markdown',
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
from selenium.webdriver.support import expected_conditions as EC
|
|
2
|
-
from selenium.webdriver.support.ui import WebDriverWait
|
|
3
|
-
from selenium.webdriver.common.by import By
|
|
4
|
-
import undetected_chromedriver as uc
|
|
5
|
-
from selenium import webdriver
|
|
6
|
-
from selenium.webdriver.remote.webelement import WebElement
|
|
7
|
-
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
|
|
8
|
-
import time
|
|
9
|
-
|
|
10
|
-
CAPABILITIES = {
|
|
11
|
-
"browserName": "chrome",
|
|
12
|
-
"version": "110.0",
|
|
13
|
-
"name": "default",
|
|
14
|
-
"enableVNC" : True,
|
|
15
|
-
"enableVideo": False,
|
|
16
|
-
"sessionTimeout": "30m"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
DEFAULT_OPTIONS = [
|
|
20
|
-
#"--disable-web-security",
|
|
21
|
-
"--verbose",
|
|
22
|
-
#"--no-sandbox",
|
|
23
|
-
"--disable-infobars",
|
|
24
|
-
"--disable-extensions",
|
|
25
|
-
"--disable-notifications",
|
|
26
|
-
"--disable-gpu",
|
|
27
|
-
'--start-maximized',
|
|
28
|
-
'--disable-blink-features=AutomationControlled',
|
|
29
|
-
'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class CWebElement(WebElement):
|
|
34
|
-
def __init__(self, *args, **kwargs):
|
|
35
|
-
super().__init__(*args, **kwargs)
|
|
36
|
-
|
|
37
|
-
def delayed_send(self, word, delay=0.5):
|
|
38
|
-
"""
|
|
39
|
-
Desc:
|
|
40
|
-
Send keys to the element with a delay between each character.\n
|
|
41
|
-
Args:
|
|
42
|
-
- ``word`` - The string to be sent to the element.
|
|
43
|
-
- ``delay`` - The delay between each character in seconds.
|
|
44
|
-
Default: 0.5 seconds.
|
|
45
|
-
"""
|
|
46
|
-
for c in word:
|
|
47
|
-
self.send_keys(c)
|
|
48
|
-
time.sleep(delay)
|
|
49
|
-
|
|
50
|
-
class CustomRemoteDriver(RemoteWebDriver):
|
|
51
|
-
def create_web_element(self, element_id):
|
|
52
|
-
return CWebElement(self, element_id)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class SeleniumUts:
|
|
56
|
-
driver = None
|
|
57
|
-
|
|
58
|
-
def close(self):
|
|
59
|
-
"""
|
|
60
|
-
Desc:
|
|
61
|
-
Close the browser.\n
|
|
62
|
-
Args: None
|
|
63
|
-
"""
|
|
64
|
-
if self.driver:
|
|
65
|
-
self.driver.quit()
|
|
66
|
-
self.driver = None
|
|
67
|
-
|
|
68
|
-
def wait_loads(self, tm=5):
|
|
69
|
-
wait = WebDriverWait(self.driver, 60)
|
|
70
|
-
wt = lambda a: self.driver.execute_script("return document.readyState==\"complete\";")
|
|
71
|
-
wait.until(wt)
|
|
72
|
-
time.sleep(tm)
|
|
73
|
-
|
|
74
|
-
def open_page(self,page):
|
|
75
|
-
"""
|
|
76
|
-
Desc:
|
|
77
|
-
Open a page in the browser.\n
|
|
78
|
-
and wait for it to load.\n
|
|
79
|
-
Args:
|
|
80
|
-
- ``page`` - The URL of the page to be opened.
|
|
81
|
-
Returns:
|
|
82
|
-
- The WebDriver instance.
|
|
83
|
-
"""
|
|
84
|
-
self.driver.get(page)
|
|
85
|
-
self.driver.implicitly_wait(2)
|
|
86
|
-
self.wait_loads()
|
|
87
|
-
|
|
88
|
-
return self.driver
|
|
89
|
-
|
|
90
|
-
def wait_xpath(self,path,time=20,throw=True):
|
|
91
|
-
"""
|
|
92
|
-
Desc:
|
|
93
|
-
Wait for an element to be visible using its XPATH.\n
|
|
94
|
-
Args:
|
|
95
|
-
- ``path`` - The XPATH of the element to be waited for.
|
|
96
|
-
- ``time`` - Maximum time to wait for the element in seconds. Default is 20 seconds.
|
|
97
|
-
- ``throw`` - If True, raises an exception if the element is not found within the time limit.
|
|
98
|
-
Returns:
|
|
99
|
-
- The WebElement if found, otherwise None.
|
|
100
|
-
"""
|
|
101
|
-
try:
|
|
102
|
-
element = WebDriverWait(self.driver, time).until(
|
|
103
|
-
EC.visibility_of_element_located((By.XPATH, path)))
|
|
104
|
-
return element
|
|
105
|
-
except:
|
|
106
|
-
if throw: raise
|
|
107
|
-
return None
|
|
108
|
-
|
|
109
|
-
def scroll_end(self):
|
|
110
|
-
"""
|
|
111
|
-
Desc:
|
|
112
|
-
Scroll to the end of the page.\n
|
|
113
|
-
Args: None
|
|
114
|
-
"""
|
|
115
|
-
|
|
116
|
-
get_pos = lambda:self.driver.execute_script("return document.documentElement.scrollTop")
|
|
117
|
-
|
|
118
|
-
while True:
|
|
119
|
-
atual_pos = get_pos()
|
|
120
|
-
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
|
|
121
|
-
time.sleep(2)
|
|
122
|
-
future_pos = get_pos()
|
|
123
|
-
if future_pos == atual_pos:
|
|
124
|
-
break
|
|
125
|
-
|
|
126
|
-
def setupSelenium(
|
|
127
|
-
self,
|
|
128
|
-
host,
|
|
129
|
-
name="default",
|
|
130
|
-
use_selenoid=False,
|
|
131
|
-
cust_opt = [],
|
|
132
|
-
remove_default_options=False,
|
|
133
|
-
download_path=None,
|
|
134
|
-
selenoid_browser=("chrome","128.0")
|
|
135
|
-
) -> webdriver:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
#===================== OPTIONS ==============================
|
|
139
|
-
options = []
|
|
140
|
-
if not remove_default_options:
|
|
141
|
-
options = DEFAULT_OPTIONS
|
|
142
|
-
options += cust_opt
|
|
143
|
-
|
|
144
|
-
web_options = uc.ChromeOptions() if not use_selenoid else webdriver.ChromeOptions()
|
|
145
|
-
for op in options:
|
|
146
|
-
web_options.add_argument(op)
|
|
147
|
-
|
|
148
|
-
web_options.headless = False
|
|
149
|
-
|
|
150
|
-
#==================== PREFERENCES ===========================
|
|
151
|
-
prefs = {
|
|
152
|
-
"download.default_directory" : download_path,
|
|
153
|
-
"download.directory_upgrade" : True,
|
|
154
|
-
"download.prompt_for_download" : False,
|
|
155
|
-
"safebrowsing.enabled" : False,
|
|
156
|
-
"credentials_enable_service" : False,
|
|
157
|
-
"profile.password_manager_enabled" : False,
|
|
158
|
-
"autofill.profile_enabled" : False,
|
|
159
|
-
"plugins.always_open_pdf_externally" : True,
|
|
160
|
-
"profile.password_manager_leak_detection": False,
|
|
161
|
-
}
|
|
162
|
-
web_options.add_experimental_option("prefs", prefs)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
#================== START BROWSER ===========================
|
|
166
|
-
|
|
167
|
-
if use_selenoid:
|
|
168
|
-
web_options.add_experimental_option("useAutomationExtension", False)
|
|
169
|
-
web_options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
|
170
|
-
|
|
171
|
-
CAPABILITIES["name"] = name
|
|
172
|
-
CAPABILITIES["browserName"] = selenoid_browser[0]
|
|
173
|
-
CAPABILITIES["version"] = selenoid_browser[1]
|
|
174
|
-
web_options.set_capability(name="selenoid:options", value=CAPABILITIES)
|
|
175
|
-
web_options.set_capability(name="browserName", value=CAPABILITIES["browserName"])
|
|
176
|
-
|
|
177
|
-
self.driver = CustomRemoteDriver(command_executor=host, options=web_options)
|
|
178
|
-
else:
|
|
179
|
-
self.driver = uc.Chrome(options=web_options)
|
|
180
|
-
|
|
181
|
-
self.driver.maximize_window()
|
|
182
|
-
self.driver.implicitly_wait(10)
|
|
183
|
-
|
|
184
|
-
return self.driver
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|