seleniumUts 1.0.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.
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.1
2
+ Name: seleniumUts
3
+ Version: 1.0.0
4
+ Summary: Zdek Util libraries for Pythom coding
5
+ Home-page: https://github.com/SymplaAutomate/selenium-lib
6
+ Author: Zdek Development team
7
+ License: MIT
8
+ Keywords: seleniumUts
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Operating System :: Microsoft :: Windows :: Windows 10
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: undetected-chromedriver>=3.5.5
17
+ Requires-Dist: selenium>=4.15.2
18
+
19
+ # SeleniumUts
20
+
21
+ Uma biblioteca Python que encapsula algumas funcionalidades do Selenium WebDriver, facilitando a automação de navegadores para testes e raspagem de dados. A biblioteca suporta o uso do `undetected_chromedriver` e integra-se facilmente com o Selenoid para execução de testes em ambientes distribuídos.
22
+
23
+ ## Uso
24
+
25
+ ### Importando a Biblioteca
26
+
27
+ ```python
28
+ from seleniumUts import SeleniumUts
29
+ ```
30
+
31
+ ### Criando uma Instância de `SeleniumUts`
32
+
33
+ ```python
34
+ selenium_lib = SeleniumUts()
35
+ ```
36
+
37
+ ### Exemplos de Uso
38
+
39
+ #### Configurando o Selenium com ChromeDriver
40
+
41
+ ```python
42
+ # Configure o Selenium sem usar o Selenoid
43
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
44
+
45
+ # Abrir uma página web
46
+ driver = selenium_lib.open_page('https://www.example.com')
47
+
48
+ # Fechar o navegador
49
+ selenium_lib.close()
50
+ ```
51
+
52
+ #### Configurando o Selenium com Selenoid
53
+
54
+ ```python
55
+ # Configure o Selenium usando o Selenoid
56
+ selenoid_host = 'http://your-selenoid-server.com/wd/hub'
57
+ selenium_lib.setupSelenium(host=selenoid_host, use_selenoid=True)
58
+
59
+ # Abrir uma página web
60
+ driver = selenium_lib.open_page('https://www.example.com')
61
+
62
+ # Fechar o navegador
63
+ selenium_lib.close()
64
+ ```
65
+
66
+ #### Aguardando a Visibilidade de um Elemento
67
+
68
+ ```python
69
+ # Configure o Selenium
70
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
71
+
72
+ # Abrir uma página web
73
+ selenium_lib.open_page('https://www.example.com')
74
+
75
+ # Esperar até que o elemento esteja visível
76
+ element = selenium_lib.wait_xpath('//button[@id="submit"]', time=10)
77
+ element.click()
78
+
79
+ # Fechar o navegador
80
+ selenium_lib.close()
81
+ ```
82
+
83
+ #### Envio de Texto com Atraso entre Caracteres
84
+
85
+ ```python
86
+ # Configure o Selenium
87
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
88
+
89
+ # Abrir uma página web
90
+ selenium_lib.open_page('https://www.example.com')
91
+
92
+ # Encontrar o campo de texto e enviar texto com atraso
93
+ element = selenium_lib.wait_xpath('//input[@id="search-box"]')
94
+ element.delayed_send('Python Selenium', delay=0.2)
95
+
96
+ # Fechar o navegador
97
+ selenium_lib.close()
98
+ ```
99
+
100
+ #### Rolagem até o Fim da Página
101
+
102
+ ```python
103
+ # Configure o Selenium
104
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
105
+
106
+ # Abrir uma página web
107
+ selenium_lib.open_page('https://www.example.com')
108
+
109
+ # Rolagem até o fim da página
110
+ selenium_lib.scroll_end()
111
+
112
+ # Fechar o navegador
113
+ selenium_lib.close()
114
+ ```
115
+
116
+ ## Métodos Disponíveis
117
+
118
+ - **`setupSelenium(host, name="default", use_selenoid=False, cust_opt=[], remove_default_options=False, download_path=None, selenoid_browser=("chrome","110.0"))`**: Configura o WebDriver do Selenium com opções personalizadas e preferências para o ChromeDriver. Suporta configuração para Selenoid.
119
+ - **`open_page(page)`**: Abre uma página web e espera até que ela seja totalmente carregada.
120
+ - **`wait_xpath(path, time=20, throw=True)`**: Aguarda até que um elemento, identificado por um caminho XPath, esteja visível no DOM.
121
+ - **`<el>.delayed_send(word, delay)`**: Envia texto para um elemento, inserindo um atraso especificado entre cada caractere.
122
+ - **`scroll_end()`**: Rola até o final da página atual.
123
+ - **`close()`**: Fecha o navegador e encerra a sessão do WebDriver.
124
+
125
+ ## Contribuição
126
+
127
+ Contribuições são bem-vindas! Por favor, envie um pull request ou abra uma issue para quaisquer problemas ou melhorias.
128
+
129
+ ## Licença
130
+
131
+ Este projeto está licenciado sob a licença MIT.
132
+
133
+
134
+ Change Log
135
+ ==========
136
+
137
+ 1.0.0 (2025-12-09)
138
+ ------------------
139
+ - First Release
@@ -0,0 +1,113 @@
1
+ # SeleniumUts
2
+
3
+ Uma biblioteca Python que encapsula algumas funcionalidades do Selenium WebDriver, facilitando a automação de navegadores para testes e raspagem de dados. A biblioteca suporta o uso do `undetected_chromedriver` e integra-se facilmente com o Selenoid para execução de testes em ambientes distribuídos.
4
+
5
+ ## Uso
6
+
7
+ ### Importando a Biblioteca
8
+
9
+ ```python
10
+ from seleniumUts import SeleniumUts
11
+ ```
12
+
13
+ ### Criando uma Instância de `SeleniumUts`
14
+
15
+ ```python
16
+ selenium_lib = SeleniumUts()
17
+ ```
18
+
19
+ ### Exemplos de Uso
20
+
21
+ #### Configurando o Selenium com ChromeDriver
22
+
23
+ ```python
24
+ # Configure o Selenium sem usar o Selenoid
25
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
26
+
27
+ # Abrir uma página web
28
+ driver = selenium_lib.open_page('https://www.example.com')
29
+
30
+ # Fechar o navegador
31
+ selenium_lib.close()
32
+ ```
33
+
34
+ #### Configurando o Selenium com Selenoid
35
+
36
+ ```python
37
+ # Configure o Selenium usando o Selenoid
38
+ selenoid_host = 'http://your-selenoid-server.com/wd/hub'
39
+ selenium_lib.setupSelenium(host=selenoid_host, use_selenoid=True)
40
+
41
+ # Abrir uma página web
42
+ driver = selenium_lib.open_page('https://www.example.com')
43
+
44
+ # Fechar o navegador
45
+ selenium_lib.close()
46
+ ```
47
+
48
+ #### Aguardando a Visibilidade de um Elemento
49
+
50
+ ```python
51
+ # Configure o Selenium
52
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
53
+
54
+ # Abrir uma página web
55
+ selenium_lib.open_page('https://www.example.com')
56
+
57
+ # Esperar até que o elemento esteja visível
58
+ element = selenium_lib.wait_xpath('//button[@id="submit"]', time=10)
59
+ element.click()
60
+
61
+ # Fechar o navegador
62
+ selenium_lib.close()
63
+ ```
64
+
65
+ #### Envio de Texto com Atraso entre Caracteres
66
+
67
+ ```python
68
+ # Configure o Selenium
69
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
70
+
71
+ # Abrir uma página web
72
+ selenium_lib.open_page('https://www.example.com')
73
+
74
+ # Encontrar o campo de texto e enviar texto com atraso
75
+ element = selenium_lib.wait_xpath('//input[@id="search-box"]')
76
+ element.delayed_send('Python Selenium', delay=0.2)
77
+
78
+ # Fechar o navegador
79
+ selenium_lib.close()
80
+ ```
81
+
82
+ #### Rolagem até o Fim da Página
83
+
84
+ ```python
85
+ # Configure o Selenium
86
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
87
+
88
+ # Abrir uma página web
89
+ selenium_lib.open_page('https://www.example.com')
90
+
91
+ # Rolagem até o fim da página
92
+ selenium_lib.scroll_end()
93
+
94
+ # Fechar o navegador
95
+ selenium_lib.close()
96
+ ```
97
+
98
+ ## Métodos Disponíveis
99
+
100
+ - **`setupSelenium(host, name="default", use_selenoid=False, cust_opt=[], remove_default_options=False, download_path=None, selenoid_browser=("chrome","110.0"))`**: Configura o WebDriver do Selenium com opções personalizadas e preferências para o ChromeDriver. Suporta configuração para Selenoid.
101
+ - **`open_page(page)`**: Abre uma página web e espera até que ela seja totalmente carregada.
102
+ - **`wait_xpath(path, time=20, throw=True)`**: Aguarda até que um elemento, identificado por um caminho XPath, esteja visível no DOM.
103
+ - **`<el>.delayed_send(word, delay)`**: Envia texto para um elemento, inserindo um atraso especificado entre cada caractere.
104
+ - **`scroll_end()`**: Rola até o final da página atual.
105
+ - **`close()`**: Fecha o navegador e encerra a sessão do WebDriver.
106
+
107
+ ## Contribuição
108
+
109
+ Contribuições são bem-vindas! Por favor, envie um pull request ou abra uma issue para quaisquer problemas ou melhorias.
110
+
111
+ ## Licença
112
+
113
+ Este projeto está licenciado sob a licença MIT.
@@ -0,0 +1,184 @@
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
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.1
2
+ Name: seleniumUts
3
+ Version: 1.0.0
4
+ Summary: Zdek Util libraries for Pythom coding
5
+ Home-page: https://github.com/SymplaAutomate/selenium-lib
6
+ Author: Zdek Development team
7
+ License: MIT
8
+ Keywords: seleniumUts
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Operating System :: Microsoft :: Windows :: Windows 10
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: undetected-chromedriver>=3.5.5
17
+ Requires-Dist: selenium>=4.15.2
18
+
19
+ # SeleniumUts
20
+
21
+ Uma biblioteca Python que encapsula algumas funcionalidades do Selenium WebDriver, facilitando a automação de navegadores para testes e raspagem de dados. A biblioteca suporta o uso do `undetected_chromedriver` e integra-se facilmente com o Selenoid para execução de testes em ambientes distribuídos.
22
+
23
+ ## Uso
24
+
25
+ ### Importando a Biblioteca
26
+
27
+ ```python
28
+ from seleniumUts import SeleniumUts
29
+ ```
30
+
31
+ ### Criando uma Instância de `SeleniumUts`
32
+
33
+ ```python
34
+ selenium_lib = SeleniumUts()
35
+ ```
36
+
37
+ ### Exemplos de Uso
38
+
39
+ #### Configurando o Selenium com ChromeDriver
40
+
41
+ ```python
42
+ # Configure o Selenium sem usar o Selenoid
43
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
44
+
45
+ # Abrir uma página web
46
+ driver = selenium_lib.open_page('https://www.example.com')
47
+
48
+ # Fechar o navegador
49
+ selenium_lib.close()
50
+ ```
51
+
52
+ #### Configurando o Selenium com Selenoid
53
+
54
+ ```python
55
+ # Configure o Selenium usando o Selenoid
56
+ selenoid_host = 'http://your-selenoid-server.com/wd/hub'
57
+ selenium_lib.setupSelenium(host=selenoid_host, use_selenoid=True)
58
+
59
+ # Abrir uma página web
60
+ driver = selenium_lib.open_page('https://www.example.com')
61
+
62
+ # Fechar o navegador
63
+ selenium_lib.close()
64
+ ```
65
+
66
+ #### Aguardando a Visibilidade de um Elemento
67
+
68
+ ```python
69
+ # Configure o Selenium
70
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
71
+
72
+ # Abrir uma página web
73
+ selenium_lib.open_page('https://www.example.com')
74
+
75
+ # Esperar até que o elemento esteja visível
76
+ element = selenium_lib.wait_xpath('//button[@id="submit"]', time=10)
77
+ element.click()
78
+
79
+ # Fechar o navegador
80
+ selenium_lib.close()
81
+ ```
82
+
83
+ #### Envio de Texto com Atraso entre Caracteres
84
+
85
+ ```python
86
+ # Configure o Selenium
87
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
88
+
89
+ # Abrir uma página web
90
+ selenium_lib.open_page('https://www.example.com')
91
+
92
+ # Encontrar o campo de texto e enviar texto com atraso
93
+ element = selenium_lib.wait_xpath('//input[@id="search-box"]')
94
+ element.delayed_send('Python Selenium', delay=0.2)
95
+
96
+ # Fechar o navegador
97
+ selenium_lib.close()
98
+ ```
99
+
100
+ #### Rolagem até o Fim da Página
101
+
102
+ ```python
103
+ # Configure o Selenium
104
+ selenium_lib.setupSelenium(host=None, use_selenoid=False)
105
+
106
+ # Abrir uma página web
107
+ selenium_lib.open_page('https://www.example.com')
108
+
109
+ # Rolagem até o fim da página
110
+ selenium_lib.scroll_end()
111
+
112
+ # Fechar o navegador
113
+ selenium_lib.close()
114
+ ```
115
+
116
+ ## Métodos Disponíveis
117
+
118
+ - **`setupSelenium(host, name="default", use_selenoid=False, cust_opt=[], remove_default_options=False, download_path=None, selenoid_browser=("chrome","110.0"))`**: Configura o WebDriver do Selenium com opções personalizadas e preferências para o ChromeDriver. Suporta configuração para Selenoid.
119
+ - **`open_page(page)`**: Abre uma página web e espera até que ela seja totalmente carregada.
120
+ - **`wait_xpath(path, time=20, throw=True)`**: Aguarda até que um elemento, identificado por um caminho XPath, esteja visível no DOM.
121
+ - **`<el>.delayed_send(word, delay)`**: Envia texto para um elemento, inserindo um atraso especificado entre cada caractere.
122
+ - **`scroll_end()`**: Rola até o final da página atual.
123
+ - **`close()`**: Fecha o navegador e encerra a sessão do WebDriver.
124
+
125
+ ## Contribuição
126
+
127
+ Contribuições são bem-vindas! Por favor, envie um pull request ou abra uma issue para quaisquer problemas ou melhorias.
128
+
129
+ ## Licença
130
+
131
+ Este projeto está licenciado sob a licença MIT.
132
+
133
+
134
+ Change Log
135
+ ==========
136
+
137
+ 1.0.0 (2025-12-09)
138
+ ------------------
139
+ - First Release
@@ -0,0 +1,8 @@
1
+ README.md
2
+ setup.py
3
+ seleniumUts/__init__.py
4
+ seleniumUts.egg-info/PKG-INFO
5
+ seleniumUts.egg-info/SOURCES.txt
6
+ seleniumUts.egg-info/dependency_links.txt
7
+ seleniumUts.egg-info/requires.txt
8
+ seleniumUts.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ undetected-chromedriver>=3.5.5
2
+ selenium>=4.15.2
@@ -0,0 +1 @@
1
+ seleniumUts
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ classifiers = [
4
+ 'Development Status :: 5 - Production/Stable',
5
+ 'Intended Audience :: Education',
6
+ 'Operating System :: Microsoft :: Windows :: Windows 10',
7
+ 'License :: OSI Approved :: MIT License',
8
+ 'Programming Language :: Python :: 3'
9
+ ]
10
+
11
+ setup(
12
+ name = 'seleniumUts',
13
+ version = '1.0.0',
14
+ packages = find_packages(),
15
+ long_description = open('README.md').read() + '\n\n' + open('CHANGELOG.txt').read(),
16
+ long_description_content_type = 'text/markdown',
17
+ install_requires = [
18
+ "undetected-chromedriver>=3.5.5",
19
+ "selenium>=4.15.2"
20
+ ],
21
+ author = 'Zdek Development team',
22
+ description = 'Zdek Util libraries for Pythom coding',
23
+ url = 'https://github.com/SymplaAutomate/selenium-lib',
24
+ license = 'MIT',
25
+ keywords = 'seleniumUts',
26
+ classifiers = classifiers,
27
+ python_requires = '>=3.10',
28
+ )